$auth->createOperation('readPost','read a post');
$role=$auth->createRole('reader');
$role->addChild('readPost');
My question: Can I have a space in the operation name? Instead of 'readPost' can I have 'Read Post'? For example:
$auth->createOperation('Read Post','read a post');
$role=$auth->createRole('reader');
$role->addChild('Read Post');
Would that be ok?
The roles and operations are all stored in the database, right? So I only have to create a role/operation once in the life of my application? (until I delete it)
To assign a role, the doc says: $auth->assign('reader','readerA');
Is the second parameter ('readerA') supposed to be the user name? What if the user changes his user name? Is it not possible to use the numeric user id that I store internally and never changes for a user?
yes, you can. This can be any string (including non-English characters).
If you are using CDbAuthManager, the data will be stored in database. And, yes, you only need to set them once, unless your system supports permission management.
This should be what Yii::app()->user->id returns. If you want to use something else, you should extend CWebUser and override its checkAccess().
I notice that the schema includes foreign keys. I use MySQL. Should I set the storage engine to InnoDB so that the foreign keys apply? (MyISAM doesn't support foreign keys).
Thanks for all the help. I have one question about the AuthAssignment table. Under the 'data' field it seems to give an 'N;' value. What does that mean?
I have several hundred users that I need to migrate to the new Yii application. I am planning to insert data directly into the AuthAssignment table, since the format looks simple enough. Is it correct to give 'N;' to everybody under the 'data' field?
The data is the serialized representation of the data property of an auth item. I think N; means it is null. You normally should use CDbAuthManager::createAuthItem() to create an auth item. By doing that, you don't need to touch that data column explicitly.
I am going to use the same things(very similar). In which file I have to add these line?
In controller/model?
Basically I have a model called User with username and password. Also another field name userRole which is an integer. Later on, I want to see the userRole field and set the role.i.e. userRole ==1 is an admin which can do all CRUD but userRole==2 can only create and and update but CANNOT delete anything.
Any hint? I am really desperate and I must do it as soon as possible.