12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\portal\controller;
- use app\portal\model\PortalPostModel;
- use cmf\controller\HomeBaseController;
- use app\portal\model\PortalCategoryModel;
- class ListController extends HomeBaseController
- {
-
- public function index()
- {
- $this->getTopNav();
-
- $id = $this->request->param('category_id', 0, 'intval');
- $portalCategoryModel = new PortalCategoryModel();
- $category = $portalCategoryModel->where(function ($query) use ($id) {
- $query->where('id', $id)->whereOr('parent_id', $id);
- })->where('status', 1)->select();
- $category_self = [];
- $category_child = [];
- foreach ($category as $v) {
- if ($v['id'] == $id) {
- $category_self = $v;
- } else {
- $category_child[] = $v;
- }
- }
- $this->assign('category_self', $category_self);
- $this->assign('category_child', $category_child);
-
- $path = explode('-', $category_self['path']);
- array_shift($path);
- $path_list = $portalCategoryModel->where('id', 'in', $path)->select();
- $this->assign('path_list', $path_list);
-
- $keyword = $this->request->param('keyword', '');
- $condition = [];
- if (!empty($keyword)) {
- $condition[] = ['post_title', 'like', "%{$keyword}%"];
- }
- $portalModel = new PortalPostModel();
- $list = $portalModel->getListByCategory($id, 10, $condition);
- $this->assign('keyword',$keyword);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- $listTpl = empty($category_self['list_tpl']) ? 'list' : $category_self['list_tpl'];
- return $this->fetch('/' . $listTpl);
- }
- }
|