[SOLVED] Chapter 8: rbac console

I created the console script based from the book.

I placed it inside my app’s protected/shell directory.

when I ran “yiic shell rbac” it’s giving me this,

btw, am using the 1.1.4 yii version, not the one from the book,

so how will i run this console script ?

The rbac is a command available once you are already in the interactive shell. Do no specify this as part of executing the command to start the shell. So, first start the interactive shell (assuming you want to load the main config.php file as your shell context):

yiic shell config/main.php

which should result in something similiar to the following (1.1.4 in your case):

Yii Interactive Tool v1.1 (based on Yii v1.1.2)

Please type ‘help’ for help. Type ‘exit’ to quit.

>>

Then at the >> prompt, type ‘help’

>>help

This will give you a list of all available commands. If rbac is in the list, you can execute it

>>rbac

Hope this helps.

this is what i got after typing the "yiic shell config/main.php"

Please try this. I don’t know about windows, but something similar works on linux mint.




C:\> cd C:\xampp\htdocs\yii\trackstar

C:\xampp\htdocs\yii\trackstar> C:\xampp\htdocs\yii\yii\framework\yiic shell

>> help

>> rbac



ok, but it didn’t help, same thing happened, are you using 1.1.4 as well ?

You’ve probably put your authManager configuration into the wrong section of the config file. It should be inside ‘components’=>array(…).

it was solved, I placed this code inside the console.php file




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

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

	'components'=>array(

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

			),

		),

	),

);



But I got a new question: where does the hierarchy goes, if it was really created ?

If you are following along with the book, and are using the CDbAuthManager implementation of auth manger, then it is using the database tables to store the hierarchy:

AuthItem

AuthItemChild

AuthAssignment

ok, but how come nothing was saved in the tables after I ran the script and even though the shell said the generation of hierarchy was successful ? ( I copied the exact code and see to it there’s no typo error ).

I didn’t read the book, so sorry, if i’m wrong because things are handled differently. But from the configuration you pasted i’d say you have not configured an authManager component at all, now.

ok, is this correct now? I just added the authmanager array inside the console.php file




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

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

	'authManager'=>array(

		'class' => 'CDbAuthManager',

		'connectionID' => 'db',

	),

	'components'=>array(

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

			),

		),

	),

);



but still none was being saved in any of those 3 tables, why?

Now you’ve again not put it inside ‘components’=>array( … )

ok here, I hoped it was correct now, but…




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

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

	'components'=>array(

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

			),

		),

		'authManager'=>array(

		'class' => 'CDbAuthManager',

		'connectionID' => 'db',

	),

	),

);



am getting this error, what’s it all about this time?, the way I understand it, it’s looking for a connection string,

I checked the main.php file and I saw this as part of the db array, but the console.php file array , has a key of “connectionID”, what’s the ID was it looking for? is the value assigned to it correct ? or do I need to replace that key value something else ?




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



problem solved




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

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

	'components'=>array(

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

			),

		),

		'db' => array(

			'class' => 'CDbConnection',

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

			'username' => 'username',

			'password' => 'password',

			'charset' => 'utf8',			

		),

		'authManager'=>array(

		'class' => 'CDbAuthManager',

		'connectionID' => 'db',

		),

	),

);



Hi,

I just read the book, i manage to run the command shell and sees that the data are written in to the DB but was stuck where I was told to create the new table with:

create table tbl_project_user_role

(

project_id INTEGER NOT NULL,

user_id INTEGER NOT NULL,

role VARCHAR(64) NOT NULL,

primary key (projectId,userId,role),

foreign key (project_id) references tbl_project (id),

foreign key (user_id) references tbl_user (id),

foreign key (role) references AuthItem (name)

);

my phpmyadmin gives me this error:

#1072 - Key column ‘projectId’ doesn’t exist in table

Anyone got into this?

check the number 9 correction of this thread

http://www.yiiframework.com/forum/index.php?/topic/11920-identified-issues/

i have the same problem, i added sasori’s code in my config/console.php but rbac doesnt appear in shell. I’m using yii 1.1.10

(this is the first time using yii, have mercy)