<?php namespace app\index\controller; use think\Db; use think\Controller; use app\admin\controller\Index as adminIndex; class Index extends Controller{ function index(){ $data = Db::table('users')->select(); //var_dump($data); $this->assign('data',$data); return view(); } 控制器的调用: // 一、使用命名空间 function index(){ $u = new \app\admin\controller\Index; $u->index(); } // 二、使用use(use app\admin\controller\Index as adminIndex;) function index(){ $u = new adminIndex; $u->index(); } // 三、使用系统方法 function index(){ $u = Controller('admin/Index'); $u->index(); } function index(){ //调用当前控制器中的方法 //一、经过$this $this->text(); echo "<hr>"; //二、经过self self::text(); echo "<hr>"; //三、经过类名 Index::text(); echo "<hr>"; //四、经过系统方法action action('text'); echo "<hr>"; //调用其余控制器中的方法 //一、经过命名空间的方式 $u = new User; $u->index(); echo "<hr>"; //二、经过系统方法action action('User/index'); echo "<hr>"; //调用其余模块中控制器中的方法 //一、经过命名空间的方式 $u = new \app\admin\controller\Index; $u->index(); echo "<hr>"; //二、经过系统方法action action('admin/Index/index'); } function text(){ echo "我是index控制器的text方法"; } }