Cannot Use Rbac

C:\wamp\www\hello\protected>yiic rbac

exception ‘CException’ with message 'Property “CDbConnection.authManager” is not

defined.’ in C:\wamp\www\yii\framework\base\CComponent.php:173

Stack trace:

#0 C:\wamp\www\yii\framework\YiiBase.php(220): CComponent->__set(‘authManager’,

Array)

#1 C:\wamp\www\yii\framework\base\CModule.php(386): YiiBase::createComponent(Arr

ay)

#2 C:\wamp\www\yii\framework\web\auth\CDbAuthManager.php(589): CModule->getCompo

nent(‘db’)

#3 C:\wamp\www\yii\framework\web\auth\CDbAuthManager.php(59): CDbAuthManager->ge

tDbConnection()

#4 C:\wamp\www\yii\framework\base\CModule.php(387): CDbAuthManager->init()

#5 C:\wamp\www\yii\framework\base\CModule.php(103): CModule->getComponent('authM

anager’)

#6 C:\wamp\www\hello\protected\commands\RbacCommand.php(137): CModule->__get('au

thManager’)

#7 C:\wamp\www\hello\protected\commands\RbacCommand.php(23): RbacCommand->ensure

AuthManagerDefined()

#8 [internal function]: RbacCommand->actionIndex()

#9 C:\wamp\www\yii\framework\console\CConsoleCommand.php(172): ReflectionMethod-

>invokeArgs(Object(RbacCommand), Array)

#10 C:\wamp\www\yii\framework\console\CConsoleCommandRunner.php(71): CConsoleCom

mand->run(Array)

#11 C:\wamp\www\yii\framework\console\CConsoleApplication.php(92): CConsoleComma

ndRunner->run(Array)

#12 C:\wamp\www\yii\framework\base\CApplication.php(180): CConsoleApplication->p

rocessRequest()

#13 C:\wamp\www\yii\framework\yiic.php(33): CApplication->run()

#14 C:\wamp\www\hello\protected\yiic.php(7): require_once(‘C:\wamp\www\yii…’)

#15 {main}

please help i cannot use rbac because of this

there might be problem in your authMamager configuration

post your code here we will help you

where is it found? in protected?

post protected/config/main.php’s modules array


<?php


// 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',

	'theme'=>'blackboot',


	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

	),


	'modules'=>array(

		// uncomment the following to enable the Gii tool

		/**/

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>false,

			// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

		),

		

	),


	// application components

		'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

			),

			'authManager'=>array(

			'class'=>'CDbAuthManager',

			'connectionID'=>'db',

			'itemTable' =>'tbl_auth_item',

			'itemChildTable' =>'tbl_auth_item_child',

			'assignmentTable' =>'tbl_auth_assignment',

			

		),

		// 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/test1.db',

		),

		// uncomment the following to use a MySQL database

		

		'db'=>array(

			'connectionString' => 'mysql:host=127.0.0.1;dbname=test1',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),

		

		'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',

	),

);

Actually the other one needed, console.php, since it’s console command you’re running.

PS. How come you have two ‘db’ keys in main.php?

you have db components twice one with sqlite and another with mysql so make them unique. and explain me in what situation did u received this error

Now im getting a another error on cmd


C:\wamp\www\hello\protected>yiic rbac

This command will create three roles: Owner, Member, and Reader

 and the following permissions:

create, read, update and delete user

create, read, update and delete project

create, read, update and delete issue

Would you like to continue? (yes|no) [no]:yes

exception 'CDbException' with message 'CDbCommand failed to execute the SQL sta

ement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]: General

error: 1 no such table: tbl_auth_assignment. The SQL statement executed was: DE

ETE FROM 'tbl_auth_assignment'' in C:\wamp\www\yii\framework\db\CDbCommand.php:

58

Stack trace:

#0 C:\wamp\www\yii\framework\db\CDbCommand.php(1302): CDbCommand->execute(Array


#1 C:\wamp\www\yii\framework\web\auth\CDbAuthManager.php(560): CDbCommand->dele

e('tbl_auth_assign...')

#2 C:\wamp\www\yii\framework\web\auth\CDbAuthManager.php(550): CDbAuthManager->

learAuthAssignments()

#3 C:\wamp\www\hello\protected\commands\RbacCommand.php(39): CDbAuthManager->cl

arAll()

#4 [internal function]: RbacCommand->actionIndex()

#5 C:\wamp\www\yii\framework\console\CConsoleCommand.php(172): ReflectionMethod

>invokeArgs(Object(RbacCommand), Array)

#6 C:\wamp\www\yii\framework\console\CConsoleCommandRunner.php(71): CConsoleCom

and->run(Array)

#7 C:\wamp\www\yii\framework\console\CConsoleApplication.php(92): CConsoleComma

dRunner->run(Array)

#8 C:\wamp\www\yii\framework\base\CApplication.php(180): CConsoleApplication->p

ocessRequest()

#9 C:\wamp\www\yii\framework\yiic.php(33): CApplication->run()

#10 C:\wamp\www\hello\protected\yiic.php(7): require_once('C:\wamp\www\yii...')

#11 {main}



and this is my console.php


<?php


// This is the configuration for yiic console application.

// Any writable CConsoleApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'My Console Application',


	// preloading 'log' component

	'preload'=>array('log'),


	// application components

	

	'components'=>array('authManager'=>array(

			'class'=>'CDbAuthManager',

			'connectionID'=>'db',

			'itemTable' =>'tbl_auth_item',

			'itemChildTable' =>'tbl_auth_item_child',

			'assignmentTable' =>'tbl_auth_assignment',

),

		'db'=>array(

		

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),

		

		

		// uncomment the following to use a MySQL database

		/*

		'db'=>array(

			'connectionString' => 'mysql:host=localhost;dbname=testdrive',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),

		*/

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

			),

		),

	),

);

Problem resolve… thank you :D

What was the problem? Wrong table naming i am guessing, right?