本文整理汇总了PHP中Rights::getAuthItemSelectOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Rights::getAuthItemSelectOptions方法的具体用法?PHP Rights::getAuthItemSelectOptions怎么用?PHP Rights::getAuthItemSelectOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rights
的用法示例。
在下文中一共展示了Rights::getAuthItemSelectOptions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUser
/**
* Displays the authorization assignments for an user.
*/
public function actionUser()
{
// Create the user model and attach the required behavior
$userClass = $this->module->userClass;
$model = CActiveRecord::model($userClass)->findByPk($_GET['id']);
$model->attachBehavior('rights', new RightsUserBehavior());
$assignedItems = $this->_authorizer->getAuthItems(null, $model->getId(), null, true);
$assignments = array_keys($assignedItems);
// Make sure we have items to be selected
$selectOptions = Rights::getAuthItemSelectOptions(null, $assignments);
if ($selectOptions !== array()) {
// Create a from to add a child for the authorization item
$form = new CForm(array('elements' => array('itemname' => array('label' => false, 'type' => 'dropdownlist', 'items' => $selectOptions)), 'buttons' => array('submit' => array('type' => 'submit', 'label' => Rights::t('core', 'Assign')))), new AssignmentForm());
// Form is submitted and data is valid, redirect the user
if ($form->submitted() === true && $form->validate() === true) {
// Update and redirect
$this->_authorizer->authManager->assign($form->model->itemname, $model->getId());
$item = $this->_authorizer->authManager->getAuthItem($form->model->itemname);
$item = $this->_authorizer->attachAuthItemBehavior($item);
Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Permission :name assigned.', array(':name' => $item->getNameText())));
$this->redirect(array('assignment/user', 'id' => $model->getId()));
}
} else {
$form = null;
}
// Create a data provider for listing the assignments
$dataProvider = new AuthItemDataProvider('assignments', array('userId' => $model->getId()));
// Render the view
$this->render('user', array('model' => $model, 'dataProvider' => $dataProvider, 'form' => $form));
}
示例2: actionUser
/**
* Displays the authorization assignments for an user.
*/
public function actionUser()
{
// Create the user model and attach the required behavior
$userClass = $this->module->userClass;
$model = CActiveRecord::model($userClass)->findByPk($_GET['id']);
$this->_authorizer->attachUserBehavior($model);
$assignedItems = $this->_authorizer->getAuthItems(null, $model->getId());
$assignments = array_keys($assignedItems);
// Make sure we have items to be selected
$assignSelectOptions = Rights::getAuthItemSelectOptions(null, $assignments);
if ($assignSelectOptions !== array()) {
$formModel = new AssignmentForm();
// Form is submitted and data is valid, redirect the user
if (isset($_POST['AssignmentForm']) === true) {
$formModel->attributes = $_POST['AssignmentForm'];
if ($formModel->validate() === true) {
// Update and redirect
$this->_authorizer->authManager->assign($formModel->itemname, $model->getId());
$item = $this->_authorizer->authManager->getAuthItem($formModel->itemname);
$item = $this->_authorizer->attachAuthItemBehavior($item);
Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Permission :name assigned.', array(':name' => $item->getNameText())));
$this->redirect(array('assignment/user', 'id' => $model->getId()));
}
}
} else {
$formModel = null;
}
// Create a data provider for listing the assignments
$dataProvider = new RAuthItemDataProvider('assignments', array('userId' => $model->getId()));
// Render the view
$this->render('user', array('model' => $model, 'dataProvider' => $dataProvider, 'formModel' => $formModel, 'assignSelectOptions' => $assignSelectOptions));
}
示例3: getAuthItemSelectOptions
public function getAuthItemSelectOptions()
{
$authorizer = Yii::app()->getComponent('authorizer');
return Rights::getAuthItemSelectOptions();
}