[Snippet] Using Yii´s authManager to fill a asmselectex-box



<?php





	$auth         = Yii::app()->authManager;


	$RoleName     = $_GET['role']; // string(rolename)


	$arrTypeMap   = array("0"=>"Operation", "1"=>"Task", "2"=>"Role");	


	$arrOptGroups = array();


	$arrSelected  = array();


	


// get all authItems and push it to a optgroup depending on its type.


	$authItems = $auth->getAuthItems();


	array_multisort($authItems);


	foreach($authItems as $authItem)


	{


		if($authItem->name != $RoleName)


			$arrOptGroups[$arrTypeMap[$authItem->type]][$authItem->name]=$authItem->description;


	}





// get all assigned authItems for the current role.


	$childs = $auth->getItemChildren($RoleName);


	foreach($childs as $child)


		array_push($arrSelected, $child->name);





// and now we hand the obtained informations to a asmselectex instance


	$this->widget('application.extensions.asmselectex.EasmSelectEx',array(


			'name'=>'assignmentList',


			'values'=>$arrOptGroups,


			'selected'=>$arrSelected,


			'attributes'=>array('title'=>"Select a Authorization Item to assign."),


			'scriptOptions'=>"addItemTarget: 'bottom', animate: true, highlight: true,


					  sortable: false, removeLabel: 'revoke', highlightAddedLabel: 'Assigned: ', 


					  highlightRemovedLabel: 'Revoked: '"


	));





?>


Your result could look like this: http://ironic.tnzr.n…mselectex/demo/

The only thing, I´m missing is a way to get the “TypeMap” dynamiclly…

(but never searched through the docs… so maybe there is one)

greets ironic

Great! But maybe it's better to use Yii features to get $_GET?

Quote

Great! But maybe it's better to use Yii features to get $_GET?

yeah, sure!

It should just be an example for asmselectex+authManager. :)