implementing some features of yii user and rights.
some tips..
After Installing Yii Users and Rights to Newly Created Yii app we have to assign dynamic roles to a user at the time of user creation .

Create a role manually

first we have to create a role manually and add some operations and/or tasks to the role according to the needs
assume the role created was 'clients'

Giving role

This is very simple , achieved by using two lines of code
save the user(assume $model->id is the user saved/created)
//assign role
$authorizer = Yii::app()->getModule("rights")->getAuthorizer();
$authorizer->authManager->assign('clients', $model->id);

Getting user role

This is also very simple
the signed user id will get using Yii::app()->user->Id
$roles=Rights::getAssignedRoles(Yii::app()->user->Id); // check for single role
foreach($roles as $role)
if($role->name == 'clients')
{
//some actions here ..
$this->redirect(array('/mailbox'));
}

Making some actions public

this should be a common need of an app.
this is also very simple when using yii rights
just use a '-' (minus) operator like
public function filters()
    {
        return array(
            'rights - publicprofile', // perform access control for CRUD operations
 
        );
    }
here the publicprofile action is public, all other actions in the same controller are under rights.

Getting all the roles

getting all the roles in the application
put this line in protected/config/main
'import'=>array(
 
        'application.modules.rights.components.dataproviders.*',
 
    ),
get all roles as a dropdown
<?php
if (Yii::app()->user->isSuperuser) {
       $all_roles=new RAuthItemDataProvider('roles', array( 
    'type'=>2,
    ));
      $data=$all_roles->fetchData();
?>
    <div>
        <label for="type_id">Type</label>
        <?php echo CHtml::dropDownList("Type",'',CHtml::listData($data,'name','name'));?> 
    </div>
<?php
}
?>
Thank you Chris for the awesome module. and thanks mishamx.



Posting Lama Posting Lebih Baru

Comments :

ada 2 komentar ke “Yii User and Rights Implementation ”
pak gendoet mengatakan...
pada  

Jual aneka barang ONLINE.

bisa di pilih mana yang pingin di order.

<----------------------------------->
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
http://bantalsilikon01.blogspot.com/
<----------------------------------->

<----------------------------------->
http://bumbupecel1.blogspot.com/
http://bumbupecel1.blogspot.com/
http://bumbupecel1.blogspot.com/
http://bumbupecel1.blogspot.com/
http://kopiluwakliar01.blogspot.com/
http://kopiluwakliar01.blogspot.com/
http://kopiluwakliar01.blogspot.com/
http://kopiluwakliar01.blogspot.com/
http://kopiluwakliar01.blogspot.com/
http://kopiluwakliar01.blogspot.com/
http://kopiluwakliar01.blogspot.com/
http://kopiluwakliar01.blogspot.com/
http://kopiluwakliar01.blogspot.com/

<----------------------------------->
Terima HARGA GROSIR dan termasuk ONGKIR

http://marinirseo.blogspot.com/
http://marinirseo.blogspot.com/
http://marinirseo.blogspot.com/
http://marinirseo.blogspot.com/

CP : 085-635-945-40

Toni mengatakan...
pada  

wah saya nggak terlalu ngerti ni soal coding :(
salam kenal ya

Poskan Komentar


Copyright © 2014 - Aldi Ferdiyan - My Facebook - Powered By Pasa Iklan / Pasang Iklan Gratis


"Yii User and Rights Implementation "

Sewa Laptop Infonindo.com - Penyewaan Laptop - Sewa Laptop di jakarta - Warta kesehatan - Warta Sehat - Profil - Seks - alkes lab - Obat Penyakit Ibu Anak