Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception handling 如何处理yii中的错误_Exception Handling_Yii_Yii Extensions_Yii Components - Fatal编程技术网

Exception handling 如何处理yii中的错误

Exception handling 如何处理yii中的错误,exception-handling,yii,yii-extensions,yii-components,Exception Handling,Yii,Yii Extensions,Yii Components,我正在使用yii开发一个应用程序。我有一个action letacmanageappointment/index。我将其规则定义如下 array('allow', // allow authenticated user to perform 'create' and 'update' actions 'actions'=>array('index','create','update','delete','updatestatus'),

我正在使用yii开发一个应用程序。我有一个action let
acmanageappointment/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,
        ));


    }
此操作只能由经过身份验证的人员访问。当我登录时,此功能工作正常。但当我注销并执行此操作时,它会给出
cdbeexception
。如何处理此异常,以及当用户注销时,如果他试图访问此url,则应在登录页面上重定向他。我该怎么做

更新:以下是我的访问规则:

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

您需要定义另一个规则,以确保拒绝未经身份验证的用户访问。这必须是最后一条规则

array('allow', // allow authenticated user to perform 'create' and 'update' actions
    'actions'=>array('index','create','update','delete','updatestatus'),
    'users'=>array('@'),
),
array('deny',
    'users'=>array('*'),
),

您需要定义另一个规则,以确保拒绝未经身份验证的用户访问。这必须是最后一条规则

array('allow', // allow authenticated user to perform 'create' and 'update' actions
    'actions'=>array('index','create','update','delete','updatestatus'),
    'users'=>array('@'),
),
array('deny',
    'users'=>array('*'),
),

正如topher在评论中提到的,您需要一个
过滤器
方法

确保控制器中有此项,否则访问规则将不起任何作用:

public function filters()
{
    return array(
        'accessControl', 
    );
}

如果它有效,当他用这个片段更新它时,给他的答案打分。

正如托弗在评论中提到的,你需要一个
过滤器
方法

确保控制器中有此项,否则访问规则将不起任何作用:

public function filters()
{
    return array(
        'accessControl', 
    );
}

如果它有效,当他用这个代码段更新它时,给他的答案打分。

检查值$user\u id。如果你没有登录,你会得到空的$user\u id

$user_id = Yii::app()->user->getId();   
$criteria = new CDbCriteria();
$criteria->condition = 'user_id='.$user_id;

当您使用此条件执行时,您会得到SQL错误检查值$user\u id。如果您未登录,您会得到空的$user\u id

$user_id = Yii::app()->user->getId();   
$criteria = new CDbCriteria();
$criteria->condition = 'user_id='.$user_id;

使用此条件执行时,会出现SQL错误

,您可以在配置文件“main.php”中设置errorHandler


在这种情况下,这将把所有异常重定向到提供的URL站点/错误。

您可以在配置文件“main.php”中设置errorHandler


在这种情况下,这将把所有异常重定向到提供的URL站点/错误。

您定义了哪些其他访问规则?没有我没有定义任何其他规则您定义了哪些其他访问规则?没有我没有定义任何其他规则nx topher,我也这样做了,现在我遇到了同样的问题,当我在网上冲浪时,我看到我必须从index.php中删除yiu debug,你能发布你的
accessRules
method吗?公共函数accessRules(){return array(array('allow',//允许所有用户执行'index'和'view'操作'=>array('view','admin')),'users'=>array('admin'),,array('allow',//允许经过身份验证的用户执行'create'和'update'操作'=>array('index','create','update','delete','updatestatus'),'users'=>array('@'),),,,;}以当前格式很难阅读。用这个和你的CDbException错误信息更新问题thnx topher,我也这样做了,现在我在冲浪时遇到了同样的问题,我看到我必须从index.php中删除yii_debug,你能发布你的
accessRules
方法吗?公共函数accessRules(){return array(array)吗('allow',//允许所有用户执行'index'和'view'操作'actions'=>array('view','admin'),'users'=>array('admin'),)、array('allow',//允许经过身份验证的用户执行'create'和'update'操作'actions'=>array('index','create','update','delete','updatestatus'),'users'=>array('@'),array('deny',//拒绝所有用户的users'=>array('*'),),;}目前的格式很难阅读。用这个和你的CDBEException错误信息更新问题谢谢ankur ji bt,我忘记的是Willem Renzema解释过的东西…谢谢ankur ji bt,我忘记的是Willem Renzema解释过的东西。。。