我为您的问题找到了 2 个解决方案:
1) 创建您自己的必须扩展 CBehavior 的登录管理器类
<?php
class RequireLogin extends CBehavior
{
public function attach($owner)
{
$owner->attachEventHandler('onBeginRequest', array($this, 'handleBeginRequest'));
}
public function handleBeginRequest($event)
{
if (Yii::app()->user->isGuest && in_array($_GET['r'],array('site/showprofile')){
$this->redirect(Yii::app()->createUrl('site/login', array('fromTv'=>"1")));
}
}
}
?>
-> add the fallowing in `protected/config/main.php`
'behaviors' => array(
'onBeginRequest' => array(
'class' => 'application.components.RequireLogin'
)
),
2)你可以使用function beforeAction($action)