<?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();
}
控制器的调用:
// 1、使用命名空间
function index(){
$u = new \app\admin\controller\Index;
$u->index();
}
// 2、使用use(use app\admin\controller\Index as adminIndex;)
function index(){
$u = new adminIndex;
$u->index();
}
// 3、使用系统方法
function index(){
$u = Controller('admin/Index');
$u->index();
}
function index(){
//调用当前控制器中的方法
//1、通过$this
$this->text();
echo "<hr>";
//2、通过self
self::text();
echo "<hr>";
//3、通过类名
Index::text();
echo "<hr>";
//4、通过系统方法action
action('text');
echo "<hr>";
//调用其他控制器中的方法
//1、通过命名空间的方式
$u = new User;
$u->index();
echo "<hr>";
//2、通过系统方法action
action('User/index');
echo "<hr>";
//调用其他模块中控制器中的方法
//1、通过命名空间的方式
$u = new \app\admin\controller\Index;
$u->index();
echo "<hr>";
//2、通过系统方法action
action('admin/Index/index');
}
function text(){
echo "我是index控制器的text方法";
}
}