调用其他controller里的变量和方法

Add this line to /config/main.php (or whatever config file you are using)

'import'=>array(
               
'application.models.*',
               
'application.controllers.*', <-- add this line
       
'application.components.*',
...



example I used in siteController

        public function hello()
       
{      
       
return 'Hello World';
       
}



proof that another controller can access the method

In another controller

        public function actionIndex()
       
{
   echo  
SiteController::hello();
       
die;
...
用以上方法无法获取到controller里面的方法,
把controller里的方法前加上static设为静态就可以了
原文地址:https://www.cnblogs.com/xiaoluozi513/p/2118639.html