本文整理汇总了PHP中Model_Category::get_by_slug方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::get_by_slug方法的具体用法?PHP Model_Category::get_by_slug怎么用?PHP Model_Category::get_by_slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::get_by_slug方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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')));
} else {
$view_file = 'subcategory';
// Products
$items = $category->products;
$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);
\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('pagination', $pagination, false);
} else {
throw new \HttpNotFoundException();
}
}
示例2: 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();
}
}