Example #1
0
 public function action_list()
 {
     $m_category = Model::factory('category');
     $cat_list = $m_category->getAll()->as_array('id');
     $cat_tree = Category::get_children_tree($cat_list);
     $where = array();
     $where['ORDER'] = 'featured DESC,id DESC';
     $cid = Arr::get($_GET, 'cid', 0) ?: 0;
     $ids = Category::get_children_ids($cat_list, $cid);
     array_push($ids, $cid);
     $where['cid'] = array('in' => $ids);
     $title = Arr::get($_GET, 'title');
     if (!empty($title)) {
         $where['title'] = array('like' => "%{$title}%");
     }
     $where['status'] = Arr::get($_GET, 'status');
     $where = array_filter($where);
     $m_article = Model::factory('article');
     $total = $m_article->count($where);
     $pager = new Pager($total, 10);
     $list = $m_article->select($pager->offset, $pager->size, $where)->as_array();
     foreach ($list as &$item) {
         $cid = $item['cid'];
         $item['cat_name'] = isset($cat_list[$cid]['name']) ? $cat_list[$cid]['name'] : '';
     }
     $this->content = View::factory('article_list');
     $this->content->list = $list;
     $this->content->pager = $pager;
     $this->content->cat_list = $cat_list;
     $this->content->cat_tree = $cat_tree;
 }