8.2 tp5跨控制器調用,方法調用


<?php
    namespace app\index\controller;
    
    use\app\index\controller\Index1 as aIndex1 ;
    class Index1{
        public function index1(){
             echo "我是index模塊下的index1控制器中的index1方法";
             /*$u = new\app\index\controller\User;
             $u-> index();*/
         }

         public function test(){
        //使用命名空間調用相同模塊下的控制器
          $u = new \app\index\controller\index1;
          $u-> index1();
          echo "<hr>";
          //調用相同模塊下的控制器
          $u = new User();
          $u->index();
          echo "<hr>";
          $u = controller('User');
          $u->index();
          echo "<hr>";
          //調用不同模塊下的控制器
          $u = controller('admin/Index');
          $u->index();
          echo "<hr>";
        //使用面向對象
        $u = new aIndex1;
        $u->index1();
         }
        public function getFunc(){
            //使用相同控制器下的方法
            $this->index1();
            echo "<hr>";
            self::index1();
            echo "<hr>";
            Index1::index1();
            echo "<hr>";
            action('index1');
            echo "<hr>";
            //調用相同模塊下不同控制器的方法
            action('User/index');
            echo "<hr>";
            $u = new User;
            $u->index();
            echo "<hr>";
            //調用不同模塊下不同控制器下的方法
            action('admin/Index/index');
            echo "<hr>";
            $u = new \app\admin\controller\Index;
            $u->index();
        }
     }
?>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM