本文整理汇总了PHP中Model_Category::find_parents方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::find_parents方法的具体用法?PHP Model_Category::find_parents怎么用?PHP Model_Category::find_parents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::find_parents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
protected function show($slug = false)
{
if (isset($sorting)) {
Model_Category::$sorting = $sorting;
}
if ($category = Model_Category::get_by_slug($slug)) {
// TODO delete this
srand($category->id);
$items = null;
$parent_category = null;
if ($category->parent_id == 0) {
$view_file = 'category';
// Categories
$items = Model_Category::find(array('where' => array('parent_id' => $category->id, 'status' => 1), 'order_by' => array('sort' => 'asc')));
if (!$items) {
$view_file = 'subcategory';
$items = $category->products;
}
} else {
$view_file = 'subcategory';
// Products
$items = $category->products;
// echo '<pre>';
// print_r($items);
// echo '</pre>';
$parent_category = Model_Category::find_one_by_id($category->parent_id);
}
\Helper::sorting($items);
// Reset to empty array if there are no result found by query
if (is_null($items)) {
$items = array();
}
// Initiate pagination
$pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 15), 'uri_segment' => null));
// Remove unwanted items, and show only required ones
$items = array_slice($items, $pagination->offset, $pagination->per_page);
$category_parents = false;
if ($parent_category) {
$parents = array();
if ($category_parents_id = Model_Category::find_parents($category->parent_id, $parents, true)) {
$category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
}
}
$stock_options = \Config::load('stock-option.db');
\Theme::instance()->set_partial('content', $this->view_dir . $view_file)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('category_parents', $category_parents, false)->set('pagination', $pagination, false)->set('manage_stock', $stock_options['manage_stock'], false)->set('hide_out_of_stock', $stock_options['hide_out_of_stock'], false);
\View::set_global('title', $category->seo->meta_title ?: $category->title);
\View::set_global('meta_description', $category->seo->meta_description ?: '');
\View::set_global('meta_keywords', $category->seo->meta_keywords ?: '');
$robots = array('meta_robots_index' => $category->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $category->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow');
\View::set_global('robots', $robots);
\View::set_global('canonical', $category->seo->canonical_links);
\View::set_global('h1_tag', $category->seo->h1_tag);
if ($category->seo->redirect_301) {
\Response::redirect($category->seo->redirect_301);
}
} else {
throw new \HttpNotFoundException();
}
}
示例2: action_index
/**
* Index page
*
* @access public
* @param $slug
*/
public function action_index($slug = false, $my_products = null)
{
$category_parents = false;
if ($my_products == 1) {
Model_Product::$filter_by_pricing_group = 'assigned';
} else {
Model_Product::$filter_by_pricing_group = 'not_assigned';
}
if ($product = Model_Product::get_by_slug($slug)) {
// Find main category
if (!empty($product->categories)) {
$parents = array();
if ($category_parents_id = Model_Category::find_parents(key($product->categories), $parents, true)) {
$category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
}
}
\Theme::instance()->set_partial('content', $this->view_dir . 'product')->set('product', $product, false)->set('category_parents', $category_parents, false)->set('product_data', $product->data, false);
} else {
throw new \HttpNotFoundException();
}
}
示例3: action_index
/**
* Index page
*
* @access public
* @param $slug
*/
public function action_index($slug = false, $my_products = null)
{
$category_parents = false;
if ($my_products == 1) {
Model_Product::$filter_by_pricing_group = 'assigned';
} else {
Model_Product::$filter_by_pricing_group = 'not_assigned';
}
if ($product = Model_Product::get_by_slug($slug)) {
// Find main category
if (!empty($product->categories)) {
$parents = array();
if ($category_parents_id = Model_Category::find_parents(key($product->categories), $parents, true)) {
$category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
}
}
$stock_options = \Config::load('stock-option.db');
if ($product->attributes[0]->stock_quantity > 0 || $stock_options['manage_stock'] && $product->attributes[0]->stock_quantity < 1 && $stock_options['hide_out_of_stock'] == 0) {
\Theme::instance()->set_partial('content', $this->view_dir . 'product')->set('product', $product, false)->set('category_parents', $category_parents, false)->set('product_data', $product->data, false)->set('allow_buy_out_of_stock', $stock_options['allow_buy_out_of_stock']);
} else {
\Messages::error('Item is not available.');
\Response::redirect('page/products');
}
\View::set_global('title', $product->seo->meta_title ?: $product->title);
\View::set_global('meta_description', $product->seo->meta_description ?: '');
\View::set_global('meta_keywords', $product->seo->meta_keywords ?: '');
$robots = array('meta_robots_index' => $product->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $product->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow');
\View::set_global('robots', $robots);
\View::set_global('canonical', $product->seo->canonical_links);
\View::set_global('h1_tag', $product->seo->h1_tag);
if ($product->seo->redirect_301) {
\Response::redirect($product->seo->redirect_301);
}
} else {
throw new \HttpNotFoundException();
}
}
示例4: find_parents
public static function find_parents($id = false, &$parents = array(), $return_requested = false)
{
if (is_numeric($id)) {
if ($category = Model_Category::find_one_by_id($id)) {
if ($category->parent_id > 0) {
$parents[$id] = $category->parent_id;
Model_Category::find_parents($category->parent_id, $parents, $return_requested);
}
}
}
if ($return_requested) {
$parents[$id] = $id;
}
return array_reverse($parents);
}