Yii Framework Forum: [SOLVED] Chapter 8: rbac console - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED] Chapter 8: rbac console help

#1 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 15 November 2010 - 12:27 AM

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,

Posted Image

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

so how will i run this console script ?
0

#2 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 15 November 2010 - 12:37 AM

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.
0

#3 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 15 November 2010 - 12:43 AM

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

Posted Image
0

#4 User is offline   Nitish Bezzala 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 12-August 10

Posted 15 November 2010 - 03:33 AM

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

0

#5 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 15 November 2010 - 03:38 AM

View PostNitish Bezzala, on 15 November 2010 - 03:33 AM, said:

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 ?

Posted Image
0

#6 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 15 November 2010 - 05:23 AM

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

#7 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 15 November 2010 - 09:25 AM

View PostMike, on 15 November 2010 - 05:23 AM, said:

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 ?

Posted Image
0

#8 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 15 November 2010 - 09:34 AM

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
0

#9 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 15 November 2010 - 09:38 AM

View Postjefftulsa, on 15 November 2010 - 09:34 AM, said:

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 ).
0

#10 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 15 November 2010 - 09:47 AM

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.
0

#11 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 15 November 2010 - 09:50 AM

View PostMike, on 15 November 2010 - 09:47 AM, said:

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?
0

#12 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 15 November 2010 - 09:54 AM

Now you've again not put it inside 'components'=>array( ... )... Posted Image
0

#13 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 15 November 2010 - 10:01 AM

View PostMike, on 15 November 2010 - 09:54 AM, said:

Now you've again not put it inside 'components'=>array( ... )... Posted Image


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,

Posted Image


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

0

#14 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 15 November 2010 - 10:34 AM

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

0

#15 User is offline   danieln 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 17-January 11

Posted 17 January 2011 - 12:18 PM

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?
0

#16 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 297
  • Joined: 05-November 10

Posted 30 January 2011 - 06:46 AM

View Postdanieln, on 17 January 2011 - 12:18 PM, said:

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.yiiframew...ntified-issues/
0

#17 User is offline   Bogdan91 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 14-November 12

Posted 14 November 2012 - 11:37 PM

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)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users