当前位置: 首页>>代码示例>>PHP>>正文


PHP Model_Category::find_one_by_id方法代码示例

本文整理汇总了PHP中Model_Category::find_one_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::find_one_by_id方法的具体用法?PHP Model_Category::find_one_by_id怎么用?PHP Model_Category::find_one_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Model_Category的用法示例。


在下文中一共展示了Model_Category::find_one_by_id方法的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')));
         } 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();
     }
 }
开发者ID:EdgeCommerce,项目名称:edgecommerce,代码行数:34,代码来源:category+copy.php

示例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();
     }
 }
开发者ID:EdgeCommerce,项目名称:edgecommerce,代码行数:59,代码来源:category.php

示例3: 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);
 }
开发者ID:EdgeCommerce,项目名称:edgecommerce,代码行数:15,代码来源:category.php

示例4: action_delete

 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Category::find_one_by_id($id)) {
             // Only delete categories without subcategories
             if (empty($item->children)) {
                 // Delete other content data like images, files, etc.
                 if (!empty($item->images)) {
                     foreach ($item->images as $image) {
                         $this->delete_image($image->image);
                         $image->delete();
                     }
                 }
                 try {
                     if (method_exists($item->seo, 'delete')) {
                         $item->seo->delete();
                     }
                     $item->delete();
                     \Messages::success('Category successfully deleted.');
                 } catch (\Database_Exception $e) {
                     // show validation errors
                     \Messages::error('<strong>There was an error while trying to delete category</strong>');
                     // Uncomment lines below to show database errors
                     //$errors = $e->getMessage();
                     //\Messages::error($errors);
                 }
             } else {
                 \Messages::error('This category has subcategories. In order to delete this category first delete all subcategories.');
             }
         }
     }
     \Response::redirect(\Input::referrer());
 }
开发者ID:EdgeCommerce,项目名称:edgecommerce,代码行数:34,代码来源:category.php


注:本文中的Model_Category::find_one_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。