thinkphp5使用全局自动加载_initialize()

浏览:5521 发布日期:2015/12/14 分类:技术分享
thinkphp5怎么使用_initialize(),从3.2.3过渡过来无效?相信看了手册的大家一定会遇到这样的问题 。
base.php<?php
namespace admin\controller;
use think\controller;
class base extends Controller
{
    public function _initialize()
    {
        $indexModel=D('index');
        
        $config=$indexModel->config();
        $this->assign('config',$config);
         
        $topnav=$indexModel->topbar_nav();
        $this->assign('topnav',$topnav);
    }
}
index.php<?php
namespace admin\controller;
use think\controller;
class Index extends base
{
    public function index()
    {
        echo $this-> fetch();
    }
}
Tips:用法和thinkphp3.2.3一样,只不过他自动生成的是默认不use think\controller的,记得加上就行。为啥不加,因为他的口号就是为了api模式,精简了
最佳答案
评论( 相关
后面还有条评论,点击查看>>