Hi,
I have created roles using Yii::app()->authManager. Is there a way I can show the current roles using CGridview? Please help.
Thanks in advance.
Hi,
I have created roles using Yii::app()->authManager. Is there a way I can show the current roles using CGridview? Please help.
Thanks in advance.
get roles as array with getAuthItems (http://www.yiiframework.com/doc/api/1.1/IAuthManager#getAuthItems-detail)
and pass it to CArrayDataProvider.
then use this CArrayDataProvider as datasource for your grid.
Hi redguy,
when I use getAuthItems I am getting the exception "Property "CAuthItem.id" is not defined."
$result=Yii::app()->authManager->getAuthItems(2);
$dataProvider=new CArrayDataProvider($result, array(
'pagination'=>array(
'pageSize'=>10,
),
));
If I check the content of the array using print_r($result) I am getting
Array ( [test role] => CAuthItem Object ( [_auth:CAuthItem:private] => CDbAuthManager Object ( [connectionID] => db [itemTable] => AuthItem [itemChildTable] => AuthItemChild [assignmentTable] => AuthAssignment [db] => CDbConnection Object ( [connectionString] => pgsql:host=localhost;port=5432;dbname=dbs_Maxsell_Version2 [username] => postgres [password] => postgres [schemaCachingDuration] => 0 [schemaCachingExclude] => Array ( ) [schemaCacheID] => cache [queryCachingDuration] => 0 [queryCachingDependency] => [queryCachingCount] => 0 [queryCacheID] => cache [autoConnect] => 1 [charset] => utf8 [emulatePrepare] => 1 [enableParamLogging] => [enableProfiling] => [tablePrefix] => [initSQLs] => [driverMap] => Array ( [pgsql] => CPgsqlSchema [mysqli] => CMysqlSchema [mysql] => CMysqlSchema [sqlite] => CSqliteSchema [sqlite2] => CSqliteSchema [mssql] => CMssqlSchema [dblib] => CMssqlSchema [sqlsrv] => CMssqlSchema [oci] => COciSchema ) [pdoClass] => PDO [_attributes:CDbConnection:private] => Array ( ) [_active:CDbConnection:private] => 1 [_pdo:CDbConnection:private] => PDO Object ( ) [_transaction:CDbConnection:private] => [_schema:CDbConnection:private] => CPgsqlSchema Object ( [columnTypes] => Array ( [pk] => serial NOT NULL PRIMARY KEY [string] => character varying (255) [text] => text [integer] => integer [float] => double precision [decimal] => numeric => timestamp [timestamp] => timestamp [time] => time => bytea [boolean] => boolean [money] => decimal(19,4) ) [_sequences:CPgsqlSchema:private] => Array ( ) [_tableNames:CDbSchema:private] => Array ( ) [_tables:CDbSchema:private] => Array ( ) [_connection:CDbSchema:private] => CDbConnection Object RECURSION [_builder:CDbSchema:private] => [_cacheExclude:CDbSchema:private] => Array ( ) [_e:CComponent:private] => [_m:CComponent:private] => ) [behaviors] => Array ( ) [_initialized:CApplicationComponent:private] => 1 [_e:CComponent:private] => [_m:CComponent:private] => ) [_usingSqlite:CDbAuthManager:private] => [showErrors] => [defaultRoles] => Array ( ) [behaviors] => Array ( ) [_initialized:CApplicationComponent:private] => 1 [_e:CComponent:private] => [_m:CComponent:private] => ) [_type:CAuthItem:private] => 2 [_name:CAuthItem:private] => test role [_description:CAuthItem:private] => [_bizRule:CAuthItem:private] => [_data:CAuthItem:private] => [_e:CComponent:private] => [_m:CComponent:private] => ) )
Thanks.
read http://www.yiiframework.com/doc/api/1.1/CArrayDataProvider
CArrayDataProvider needs some ‘identifier’ in every object in array. By default it tries to access ‘id’ attribute, but you can configure it to something different, like:
$dataProvider=new CArrayDataProvider($result, array(
'id'=>'name',
'pagination'=>array(
'pageSize'=>10,
),
));
It is still showing the same error.
See the documentation: getAuthItems(2) (the same as getRoles()) returns an array(name=>CAuthItem).
Your rolenames are the array_keys of the result.
$result = array_keys(Yii::app()->authManager->getRoles())
Thanks Joblo. It is working. I want to create a user interface for Role Based User Management. I was able to create a screen for creating roles. It has a text field for entering the role name and , I am displaying the roles using CGridview. I cannot find the function to remove a role. Whether I have to write my own query for deleting the role. Similarly what is the best approach for developing the UI for creating and deleting tasks and operations.
Thanks.