首先修改一下/config/main.php
'import'=>array(
'application.models.*',
'application.controllers.*', <-- 加入這行
'application.components.*',
...
接著假設bTestController要使用aTestController的showMe這個function
class aTestController extends Controller
{
publice function showMe($name,$about)
{
$introduction='名字'.$name.'<br>關於我<br>'.$about;
return $introduction;
}
}
class bTestController extends Controller
{
publice actionTest
{
$name='Joker';
$about='就是個愛睡覺發呆的人';
$introduction=aTestController:: showMe($name,$about);
}
}
參考以下的資料
如何在yii的controller中调用外部action
调用其他controller里的变量和方法
沒有留言:
張貼留言