打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
tp5 方法控制器的调用
1、命名空间
2、use方法
3、使用系统方法
<?php
    namespace app\index\controller;
    use\app\index\controller\Index as adminIndex;
    class test1{
        public function test1(){
             echo "我是index模块下的test1控制器中的test1方法";
        }
         public function test(){
          //相同模块下
          $u = new User();
          $u->index();
          echo "<hr>";
          $u = controller('User');
          $u->index();
          echo "<hr>";
          //不同模块下
          $u = controller('admin/Index');
          $u->index();
          echo "<hr>";
         //使用命名空间调用相同模块下的控制器
          $u = new \app\admin\controller\index;
          $u-> test1();
          echo "<hr>";
        //使用面向对象
        $u = new adminIndex;
        $u->test1();
         }
        public function getFunc(){
            //使用相同控制器下的方法
            $this->test1();
            echo "<hr>";
            self::test1();
            echo "<hr>";
            test1::test1();
            echo "<hr>";
            action('test1');
            echo "<hr>";
            //调用相同模块下不同控制器的方法
            action('User/test');
            echo "<hr>";
            $u = new User;
            $u->test();
            echo "<hr>";
            //调用不同模块下不同控制器下的方法
            action('admin/Index/index');
            echo "<hr>";
            $u = new \app\admin\controller\Index;
            $u->index();
        }
        public function test1(){
            echo "我是测试方法的方法";
        }
     }
?>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ThinkPHP 模块与操作
PHP路由原理
【PHP】简单的MVC实例
5.路由
phpcms学习总结
TP框架中APP_SUB_DOMAIN_DEPLOY什么意思?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服