本文整理汇总了PHP中AuthItem::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthItem::setAttributes方法的具体用法?PHP AuthItem::setAttributes怎么用?PHP AuthItem::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthItem
的用法示例。
在下文中一共展示了AuthItem::setAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Create permission form
*/
public function actionCreate($type = null)
{
// Check Access
checkAccessThrowException('op_permission_create');
$model = new AuthItem();
if (isset($_POST['AuthItem'])) {
$model->setAttributes($_POST['AuthItem']);
if ($model->save()) {
fok(at('Permission Created!'));
// Log Message
alog(at("New permission created: '{name}'.", array('{name}' => $model->name)));
$this->redirect(array('index'));
}
} else {
if ($type !== null) {
$model->type = $type;
}
}
// Add Breadcrumb
$this->addBreadCrumb(at('Create Permission'));
$this->title[] = at('Create Permission');
$this->render('form', array('model' => $model));
}
示例2: actionCreate
/**
* Create a new auth item.
*/
public function actionCreate($type) {
if (!array_key_exists($type, $this->types))
throw new CHttpException(404, Yii::t('RbamModule.rbam','Invalid authorisation item type.'));
$authItem = new AuthItem('create'); // $authItem is a CFormModel
$authItem->setAttributes(compact('type'));
$form = $authItem->getForm();
if ($form->submitted($form->uniqueId)) {
$response = array();
if ($authItem->save()) {
$response['content'] = Yii::t('RbamModule.rbam','"{item}" {type} created.', array(
'{item}'=>$authItem->name,
'{type}'=>$this->type($type, true)
));
$response['redirect'] = $this->createUrl('manage', array('item'=>$authItem->name));
}
else {
$errors = array();
foreach ($authItem->getErrors() as $attribute=>$attributeErrors)
foreach ($attributeErrors as $error)
$errors[] = array(
'attribute'=>$attribute,
'label'=>$authItem->getAttributeLabel($attribute),
'error'=>$error
);
$response = compact('errors');
}
header('Content-type: application/json');
echo CJSON::encode($response);
Yii::app()->end();
}
$this->pageTitle = $this->_pageTitle($this->action->id, array(
'{type}'=>$this->type($type, true, true)
));
$this->breadcrumbs = array(
'RBAM'=>array('rbam/index'),
$this->_pageTitle('index')=>array('index'),
$this->pageTitle
);
$this->render('form', compact('form', 'type'));
}