0801THINKPHP基础:控制器、方法的调用

<?php
namespace appindexcontroller;
use thinkDb;
use thinkController;
use appadmincontrollerIndex 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 appadmincontrollerIndex;
        $u->index();
    }
//    2、使用use(use appadmincontrollerIndex 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 appadmincontrollerIndex;
        $u->index();
        echo "<hr>";
        //2、通过系统方法action
        action('admin/Index/index');    
    }
    function text(){
        echo "我是index控制器的text方法";
    }
}
原文地址:https://www.cnblogs.com/zhangbaozhong/p/9401871.html