How To View Roles That Assign To Users In User Gridview?

hi all,

i want to view roles that i assign to users in my user(view) gridview(i used yii rights extension).

this is my user table

CREATE TABLE IF NOT EXISTS alt_user (

id int(11) NOT NULL AUTO_INCREMENT,

first_name varchar(255) DEFAULT NULL,

middle_name varchar(255) DEFAULT NULL,

last_name varchar(255) DEFAULT NULL,

username varchar(30) NOT NULL,

password varchar(255) NOT NULL,

email varchar(255) NOT NULL,

picture text,

birthday date DEFAULT NULL,

country varchar(30) DEFAULT NULL,

address text,

tele varchar(20) DEFAULT NULL,

fax varchar(20) DEFAULT NULL,

web text,

status enum(‘Active’,‘Inactive’) NOT NULL DEFAULT ‘Active’,

date_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

PRIMARY KEY (id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=24 ;

how i do that? plz help me…

thanks chamara

can any one help me?

http://www.yiiframework.com/forum/index.php/topic/25909-how-to-toggle-column-visibility-in-cgridview/

i mean i want to show roles that assign for users using RBAC.(i want to show in gridview as this)

ex:-

name--------email-----------------role

chamara-----abc@gmail.com —admin,user

it comes from AuthItem and authassignment table

code you written are good, but more confusing, try to take a variable diffrent.

use this code to get assigned role in yii rights


$roles=Rights::getAssignedRoles(Yii::app()->user->Id);

foreach($roles as $role)

{

echo $role->name;

}

check this

http://www.yiiframework.com/wiki/448/assigning-dynamic-roles-to-a-user-using-yii-rights-module-at-the-time-of-user-creation-and-using-some-special-advanced-features-of-yii-rights/




$roles=Rights::getAssignedRoles(Yii::app()->user->Id);

foreach($roles as $role)

{

echo $role->name;

}



http://www.yiiframework.com/wiki/448/assigning-dynamic-roles-to-a-user-using-yii-rights-module-at-the-time-of-user-creation-and-using-some-special-advanced-features-of-yii-rights/

thanks rajith

i got it but i want to view it in grid as following attach file

thanks

thats very simple set a function in model

Example in the gridview colomns




'columns'=>array(

		

		

	array(

            'header'=>'Student Name',

	    'value'=>array($model,'studentname'),

	    'name'=> 'firstname',

            'sortable'=>true,


		

		),



in the model write a method named studentname




public function studentname($data,$row)

    {

		$student = Students::model()->findByAttributes(array('id'=>$data->student_id));

		if($student!=NULL)

		{

		return $student->first_name;

		}

		else

		{

			return '-';

		}

		

	}




did you got my example ?

for your code




'columns'=>array(

                

                

        array(

            'header'=>'Roles',

            'value'=>array($model,'roles'),

            'name'=> 'role',

            'sortable'=>true,


                

                ),




public function roles($data,$row)

    {

                $roles=Rights::getAssignedRoles($data->id);

                $assignedrole = '';

                foreach($roles as $role)

                {


                $assignedrole = $assignedrole.$role->name;

                

                }

                return $assignedrole ;

      }

try this

you can also set in the controller!! Gridview is very flexible!

i did it thanks for all specially rajith

//model

public function ShowAllRolesUsers($id) {

    $roles = Rights::getAssignedRoles($id);


    $users = array();


    foreach ($roles as $role)


        $users[] = $role->name;


    return implode(",", $users);


}

//grid view

    array('name' => 'role', 'header' => 'Assigned role','value'=>'$data->ShowAllRolesUsers($data->id)'),

welcome :) :)