我正在使用yii处理应用程序。我有一个行动让acmanageappointments/index
。我已经确定了它的规则如下如何处理yii中的错误
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,那么他应该在登录页面上重定向。我怎样才能做到这一点 ?
更新:这是我的accessrules:
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
您定义了哪些其他访问规则? – topher 2013-02-16 11:30:02
不,我还没有定义任何其他规则 – 2013-02-16 11:30:32