我正在使用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