我正在使用 yii 开发一个应用程序。我有一个动作让acmanageappointments/index
。我已将其规则定义如下
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('index','create','update','delete','updatestatus'),
'users'=>array('@'),
其作用如下:
public function actionIndex()
{
$user_id = Yii::app()->user->getId();
$criteria = new CDbCriteria();
$criteria->condition = 'user_id='.$user_id;
$count=AcAppointments::model()->count($criteria);
$pages=new CPagination($count);
//results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$AllAppointments = AcAppointments::model()->findAll($criteria);
// Applying Global Date Time Format
$condition = array('user_id' => $user_id);
$DTFormat = CalendarSettings::model()->findByAttributes($condition);
$this->render('index',array(
'AllAppointments' => $AllAppointments,
'pages' => $pages,
'DTFormat' => $DTFormat,
));
}
此操作只能由经过身份验证的人员访问。当我登录时,此功能正常工作。但是当我注销并执行此操作时,它会给出CDbException
. 我该如何处理这个异常,当用户退出时,如果他试图访问这个 url,那么他应该被重定向到 login page 。我怎样才能做到这一点 ?
更新:这是我的访问规则:
public function accessRules()
{
return array(
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('index','create','update','delete','updatestatus'),
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
这是错误:
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1