* @version 0.0.6 */ namespace app\index\controller; use think\facade\View; use think\App; use app\common\model\Article; use app\common\model\Category; use think\facade\Env; abstract class Base { /** * Request实例 * @var \think\Request */ protected $request; /** * 应用实例 * @var \think\App */ protected $app; /** * 构造方法 * @access public * @param App $app 应用对象 */ public function __construct(App $app) { $this->app = $app; $this->request = $this->app->request; // 控制器初始化 $this->initialize(); } // 初始化 protected function initialize() { // 菜单 $categories = Category::where('is_nav', 1)->order(['sort desc'])->select(); View::assign('categories', $categories); if ($this->request->has('_aside')==false) { $this->aside(); } } /** * 侧边栏 */ protected function aside() { $cate_lists = Category::where('template', 'article')->select(); $hits_lists = Article::getListByCid(0, 9, ['hits' => 'desc']); $top_lists = Article::getTop(7); $time_lists = Article::createTimeArchive(); View::assign([ 'cate_lists' => $cate_lists, 'hits_lists' => $hits_lists, 'top_lists' => $top_lists, 'time_lists' => $time_lists ]); } }