Module(模块)中控制器未登录验证不起作用问题

网站后台在所有Controller文件中均加了


	public function filters()

    {

        return array(

            'accessControl',

        );

    }

	public function accessRules()

    {

        return array(

            array('allow',

                'users'=>array('@'),

            ),

            array('deny',

                'users'=>array('*'),

            ),

        );

    }



来判断用户是否登录,如果未登录则跳转到登录页面。

但近来一次在未登录后台的情况下访问试验发现,

直接在地址栏中输入地址

[font="Arial Black"]h ttp://localhost/mysite/index.php?r=module/controller/action[/font]

该访问不会因为用户未登录而自动跳转到登录页面,而出现以下错误:


CDbException

Description

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 'LIMIT 1' at line 1


Source File

D:\APMServ5.2.6\www\htdocs\yii\framework\db\CDbCommand.php(387)


00375: 

00376:             if($this->_connection->enableProfiling)

00377:                 Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');

00378: 

00379:             return $result;

00380:         }

00381:         catch(Exception $e)

00382:         {

00383:             if($this->_connection->enableProfiling)

00384:                 Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');

00385:             Yii::log('Error in querying SQL: '.$this->getText().$par,CLogger::LEVEL_ERROR,'system.db.CDbCommand');

00386:             $errorInfo = $e instanceof PDOException ? $e->errorInfo : null;

00387:             throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',

00388:                 array('{error}'=>$e->getMessage())),(int)$e->getCode(),$errorInfo);

00389:         }

00390:     }

00391: }



发现此错误后再次试验直接访问模块地址而不添加Controller及Action地址

[font="Arial Black"]h ttp://localhost/mysite/index.php?r=module[/font]

此访问的结果不会出现错误,将会因为用户未登录直接跳转到登录页面

请问以上问题是什么原因,应当怎么解决?

报错的原因是sql语句错误,错误sql语句位置在limit附近。如果想没有登录的,自动跳转到登录页面可以在protected/config/main.php 里面这样设置,compontents里面添加

‘user’=>array(

// enable cookie-based authentication


'allowAutoLogin'=>true,


    'loginUrl'=>array('users/login'), // 可以在这里指定你的登陆页面的action

) ,

程序已经在main.php中配置了




'user'=>array(

  // enable cookie-based authentication

  'allowAutoLogin'=>true,

  'loginUrl'=>array('admin/login'),

),



虽然从提示上看错误的原因应当是因为数据库,但从实际和逻辑上却讲不通呀。

首先,在module下的controller中的对应action里边并没有数据库操作的程序。

其次,从程序运行逻辑上讲,此程序在接到访问要求后的第一件事应当是登录验证,然后才是执行相应action对应的操作,所以也不应当出现这个问题。