Yii 的srbac配置后,出现错误 SDbAuthManager是无效的 [ 新手入门 ]
出现如下异常:请问是哪个地方配得不对呢?CException 别名 "modules.srbac.components.SDbAuthManager" 是无效的. 请确定它指向一个已存在的目录或文件.
D:\skill\finance\Yii\protected\modules\srbac\SrbacModule.php(244)
232 public function getShowFooter() {
233 return $this->_showFooter;
234 }
235
236
237
238 /**
239 * Checks if srbac is installed by checking if Auth items table exists.
240 * @return boolean Whether srbac is installed or not
241 */
242 public function isInstalled() {
243 try {
244 $tables = Yii::app()->authManager->db->schema->tableNames;
245 $itemTableName = Yii::app()->authManager->itemTable;
246 $itemChildTableName = Yii::app()->authManager->itemChildTable ;
247 $assignmentTableName = Yii::app()->authManager->assignmentTable ;
248 $tablePrefix = AuthItem::model()->getDbConnection()->tablePrefix;
249 if(!is_null($tablePrefix)) {
250 $itemTableName = preg_replace('/{{(.*?)}}/',$tablePrefix.'\1',$itemTableName);
251 $itemChildTableName = preg_replace('/{{(.*?)}}/',$tablePrefix.'\1',$itemChildTableName);
252 $assignmentTableName = preg_replace('/{{(.*?)}}/',$tablePrefix.'\1',$assignmentTableName);
253 }
254 if(in_array($itemTableName, $tables) &&
255 in_array($itemChildTableName, $tables) &&
256 in_array($assignmentTableName, $tables)) {
[/code]我的配置文件:[code]<?php
//add by
header("Content-type: text/html; charset=utf-8");
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',
//add by
'language'=>'zh_cn',
'timeZone'=>'Asia/Shanghai',
'charset'=>'UTF-8',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.srbac.controllers.SBaseController',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'1234',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
//'ipFilters'=>array('127.0.0.1','::1'),
),
'srbac' => array(
'userclass'=>'User', //default: User
'userid'=>'user_ID', //default: userid
'username'=>'username', //default:username
'delimeter'=>'@', //default:-
'debug'=>true, //default :false
'pageSize'=>10, // default : 15
'superUser' =>'Authority', //default: Authorizer
'css'=>'srbac.css', //default: srbac.css
'layout'=>'application.views.layouts.main', //default: application.views.layouts.main,
//must be an existing alias
'notAuthorizedView'=> 'srbac.views.authitem.unauthorized', // default:
//srbac.views.authitem.unauthorized, must be an existing alias
'alwaysAllowed'=>array( //default: array()
'SiteLogin','SiteLogout','SiteIndex','SiteAdmin',
'SiteError', 'SiteContact'),
'userActions'=>array('Show','View','List'), //default: array()
'listBoxNumberOfLines' => 15, //default : 10 'imagesPath' => 'srbac.images', // default: srbac.images 'imagesPack'=>'noia', //default: noia 'iconText'=>true, // default : false 'header'=>'srbac.views.authitem.header', //default : srbac.views.authitem.header,
//must be an existing alias 'footer'=>'srbac.views.authitem.footer', //default: srbac.views.authitem.footer,
//must be an existing alias 'showHeader'=>true, // default: false 'showFooter'=>true, // default: false
'alwaysAllowedPath'=>'srbac.components', // default: srbac.components
// must be an existing alias )
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to enable URLs in path-format
/*
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
*/
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=test',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'a',
'charset' => 'utf8',
),
'db'=>array(
'class'=>'CDbConnection',
'connectionString'=>'mysql:host=localhost;dbname=test',
'username'=>'root',
'password'=>'a',
),
//Configure AuthManager component
'authManager'=>array(
// Path to SDbAuthManager in srbac module if you want to use case insensitive
//access checking (or CDbAuthManager for case sensitive access checking)
'class'=>'modules.srbac.components.SDbAuthManager',
// The database component used
'connectionID'=>'db',
// The itemTable name (default:authitem)
'itemTable'=>'items',
// The assignmentTable name (default:authassignment)
'assignmentTable'=>'assignments',
// The itemChildTable name (default:authitemchild)
'itemChildTable'=>'itemchildren',
),
//Configure srbac module:
//'import'=>array(
//'application.modules.srbac.controllers.SBaseController',
//),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster@example.com',
),
);
共 19 条回复
-
这个问题,很明显是你指定的文件路径不对。你写的配置要跟你工程的文件对应,否则就会找不到文件,你的配置:
'authManager'=>array( // Path to SDbAuthManager in srbac module if you want to use case insensitive //access checking (or CDbAuthManager for case sensitive access checking) 'class'=>'modules.srbac.components.SDbAuthManager', // 这里这个路径不能乱写,得跟你工程文件匹配 // The database component used 'connectionID'=>'db',
你看下你工程中存在这个文件:
modules/srbac/components/SDbAuthManager.php
么?Yii的components是根据类名反射查找的文件名,如果类名跟文件名不统一就会存在这个问题。
-
应该是srbac的配置文件有问题。
'srbac' => array( 'userclass'=>'User', //default: User 'userid'=>'user_ID', //default: userid 'username'=>'username', //default:username 'delimeter'=>'@', //default:- 'debug'=>true, //default :false 'pageSize'=>10, // default : 15 'superUser' =>'Authority', //default: Authorizer 'css'=>'srbac.css', //default: srbac.css 'layout'=>'application.views.layouts.main', //default: application.views.layouts.main, //must be an existing alias 'notAuthorizedView'=> 'srbac.views.authitem.unauthorized', // default: //srbac.views.authitem.unauthorized, must be an existing alias 'alwaysAllowed'=>array( //default: array() 'SiteLogin','SiteLogout','SiteIndex','SiteAdmin', 'SiteError', 'SiteContact'), 'userActions'=>array('Show','View','List'), //default: array() 'listBoxNumberOfLines' => 15, //default : 10 'imagesPath' => 'srbac.images', // default: srbac.images 'imagesPack'=>'noia', //default: noia 'iconText'=>true, // default : false 'header'=>'srbac.views.authitem.header', //default : srbac.views.authitem.header, //must be an existing alias 'footer'=>'srbac.views.authitem.footer', //default: srbac.views.authitem.footer, //must be an existing alias 'showHeader'=>true, // default: false 'showFooter'=>true, // default: false 'alwaysAllowedPath'=>'srbac.components', // default: srbac.components // must be an existing alias ) ),
这些都对应对了吗?我看怎么还是默认的值呢?
-
因为我是通过
http://localhost/Yii/index.php?r=Test/admin
访问的,这个文件的路径D:\skill\finance\Yii\protected\modules\srbac\SrbacModule.php
,那全路径是否就是:'class'=>'Yii.protected.modules.srbac.components.SDbAuthManager'
, 改为这个也是相同的错误:别名"Yii.protected.modules.srbac.components.SDbAuthManager"
是无效的. 请确定它指向一个已存在的目录或文件.
onunix china
注册时间:2012-03-19
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝2
- 金钱1145
- 威望0
- 积分1145