调用其他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设为静态就可以了
posted @ 2011-07-27 17:26  xiaoluozi513  阅读(1171)  评论(0编辑  收藏  举报