本文整理汇总了PHP中Roles::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::save方法的具体用法?PHP Roles::save怎么用?PHP Roles::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::save方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(RolesRequest $request)
{
//
$checked = [];
$roles = new Roles();
$roles->name = Input::get('name');
$roles->access = json_encode(Input::get('access'));
// $roles->name = Input::get('name');
$roles->save();
Session::flash('message', 'You have successfully added Roles');
return Redirect::to('roles');
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Roles();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Roles'])) {
$model->attributes = $_POST['Roles'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->rid));
}
}
$this->render('create', array('model' => $model));
}
示例3: actionCreate
public function actionCreate()
{
$this->breadcrumbs = array($this->ID . ' Manager' => array('index'), 'Create' => array('create'));
$model = new Roles();
if (isset($_POST['Roles'])) {
$model->attributes = $_POST['Roles'];
if ($model->validate()) {
$model->save();
Yii::app()->db->createCommand('insert into authitem(name, type, description) values(:name, 2, :description)')->execute(array(':name' => $model->alias, ':description' => $model->title));
$this->redirect(array('roles/index'));
}
}
$this->render('create', array('model' => $model));
}
示例4: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Roles();
$fecha = strftime("%Y-%m-%d-%H-%M-%S", time());
$model->FechaGraba = $fecha;
$model->FechaModifica = $fecha;
$model->IdUsuarioGraba = Yii::app()->user->id;
$model->IdUsuarioModifica = Yii::app()->user->id;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Roles'])) {
$model->attributes = $_POST['Roles'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->IdRol));
}
}
$this->render('create', array('model' => $model));
}
示例5: actionManageRoles
/**
* A catch all page for roles.
*
* This action renders a page with forms for the creation, editing, and deletion
* of roles. It also displays a grid with all user created roles (default
* roles are not included and cannot be edited this way).
*/
public function actionManageRoles()
{
$dataProvider = new CActiveDataProvider('Roles');
$roles = Yii::app()->db->createCommand()->select('id, name')->from('x2_roles')->queryAll();
$model = new Roles();
$model->timeout = 60;
$roleInput = FilterUtil::filterArrayInput($_POST, 'Roles');
if (!empty($roleInput)) {
$model->attributes = $roleInput;
$model->users = '';
$viewPermissions = FilterUtil::filterArrayInput($_POST, 'viewPermissions');
$editPermissions = FilterUtil::filterArrayInput($_POST, 'editPermissions');
$users = FilterUtil::filterArrayInput($roleInput, 'users');
$model->timeout *= 60;
if ($model->timeout === 0) {
$model->timeout = null;
}
$model->setUsers($users);
$model->setViewPermissions($viewPermissions);
$model->setEditPermissions($editPermissions);
if ($model->save()) {
} else {
foreach ($model->getErrors() as $err) {
$errors = $err;
}
$errors = implode(',', $errors);
Yii::app()->user->setFlash('error', Yii::t('admin', "Unable to save role: {errors}", array('{errors}' => $errors)));
}
$this->redirect('manageRoles');
}
$this->render('manageRoles', array('dataProvider' => $dataProvider, 'model' => $model, 'roles' => $roles));
}
示例6: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new User();
$profile = new Profile();
$roles = new Roles();
$this->performAjaxValidation(array($model, $profile));
if (isset($_POST['User'])) {
$model->attributes = $_POST['User'];
$model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
$profile->attributes = $_POST['Profile'];
$roles->attributes = $_POST['Roles'];
$profile->user_id = 0;
if ($model->validate() && $profile->validate() && $roles->validate()) {
$model->password = Yii::app()->controller->module->encrypting($model->password);
if ($model->save()) {
$profile->user_id = $model->id;
$profile->save();
$roles->save();
}
$this->redirect(array('view', 'id' => $model->id));
} else {
$profile->validate();
}
}
$this->render('_form', array('model' => $model, 'profile' => $profile, 'roles' => $roles));
}
示例7: createRole
function createRole($aData)
{
$con = Propel::getConnection(RolesPeer::DATABASE_NAME);
try {
$con->begin();
$sRolCode = $aData['ROL_CODE'];
$sRolSystem = $aData['ROL_SYSTEM'];
$status = $fields['ROL_STATUS'] = 1 ? 'ACTIVE' : 'INACTIVE';
$oCriteria = new Criteria('rbac');
$oCriteria->add(RolesPeer::ROL_CODE, $sRolCode);
$oCriteria->add(RolesPeer::ROL_SYSTEM, $sRolSystem);
$oDataset = RolesPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
$aRow = $oDataset->getRow();
if (is_array($aRow)) {
return $aRow;
}
if (!isset($aData['ROL_NAME'])) {
$aData['ROL_NAME'] = '';
}
$rol_name = $aData['ROL_NAME'];
unset($aData['ROL_NAME']);
$obj = new Roles();
$obj->fromArray($aData, BasePeer::TYPE_FIELDNAME);
if ($obj->validate()) {
$result = $obj->save();
$con->commit();
$obj->setRolName($rol_name);
G::auditLog("CreateRole", "Role Name: " . $rol_name . " - Role Code: " . $aData['ROL_CODE'] . " - Role Status: " . $status);
} else {
$e = new Exception("Failed Validation in class " . get_class($this) . ".");
$e->aValidationFailures = $this->getValidationFailures();
throw $e;
}
return $result;
} catch (exception $e) {
$con->rollback();
throw $e;
}
}
示例8: create_role
public function create_role($rol)
{
$role = new Roles();
$role->setRole($rol);
$role->save();
}
示例9: saveRoleAction
public function saveRoleAction()
{
Input::flash();
$data = Input::all();
$rules = array('rolename' => array('min:3', 'required'));
// Build the custom messages array.
$messages = array('rolename.min' => 'ชื่อบทบาทจะต้องยาวมากกว่า :min ตัวอักษร', 'rolename.required' => 'กรุณาระบุชื่อบทบาท');
// Create a new validator instance.
$validator = Validator::make($data, $rules, $messages);
if ($validator->passes()) {
$role = new Roles();
$ck_role = $this->roleObj->checkRole($data['rolename']);
if ($ck_role) {
$role->role_name = $data['rolename'];
$role->save();
return Redirect::to('role')->with('success', 'บันทึกสำเร็จ');
} else {
return Redirect::to('role-add')->with('warning', 'มีชื่อบทบาทนี้ในระบบแล้ว');
}
} else {
// $errors = $validator->messages();
return Redirect::to('role-add')->withErrors($validator);
}
}
示例10: actionManageRoles
/**
* A catch all page for roles.
*
* This action renders a page with forms for the creation, editing, and deletion
* of roles. It also displays a grid with all user created roles (default
* roles are not included and cannot be edited this way).
*/
public function actionManageRoles()
{
$dataProvider = new CActiveDataProvider('Roles');
$roles = $dataProvider->getData();
$arr = array();
foreach ($roles as $role) {
$arr[$role->name] = $role->name;
}
$temp = Workflow::model()->findAll();
$workflows = array();
foreach ($temp as $workflow) {
$workflows[$workflow->id] = $workflow->name;
}
$model = new Roles();
$model->timeout = 60;
if (isset($_POST['Roles'])) {
$model->attributes = $_POST['Roles'];
if (!isset($_POST['viewPermissions'])) {
$viewPermissions = array();
} else {
$viewPermissions = $_POST['viewPermissions'];
}
if (!isset($_POST['editPermissions'])) {
$editPermissions = array();
} else {
$editPermissions = $_POST['editPermissions'];
}
if (isset($_POST['Roles']['users'])) {
$users = $model->users;
} else {
$users = array();
}
$model->users = "";
$model->timeout *= 60;
if ($model->save()) {
foreach ($users as $user) {
$role = new RoleToUser();
$role->roleId = $model->id;
if (!is_numeric($user)) {
$userRecord = User::model()->findByAttributes(array('username' => $user));
$role->userId = $userRecord->id;
$role->type = 'user';
} else {
$role->userId = $user;
$role->type = 'group';
}
/* end x2temp */
$role->save();
}
$fields = Fields::model()->findAll();
$temp = array();
foreach ($fields as $field) {
$temp[] = $field->id;
}
$both = array_intersect($viewPermissions, $editPermissions);
$view = array_diff($viewPermissions, $editPermissions);
$neither = array_diff($temp, $viewPermissions);
foreach ($both as $field) {
$rolePerm = new RoleToPermission();
$rolePerm->roleId = $model->id;
$rolePerm->fieldId = $field;
$rolePerm->permission = 2;
$rolePerm->save();
}
foreach ($view as $field) {
$rolePerm = new RoleToPermission();
$rolePerm->roleId = $model->id;
$rolePerm->fieldId = $field;
$rolePerm->permission = 1;
$rolePerm->save();
}
foreach ($neither as $field) {
$rolePerm = new RoleToPermission();
$rolePerm->roleId = $model->id;
$rolePerm->fieldId = $field;
$rolePerm->permission = 0;
$rolePerm->save();
}
} else {
foreach ($model->getErrors() as $err) {
$errors = $err;
}
$errors = implode(',', $errors);
Yii::app()->user->setFlash('error', Yii::t('admin', "Unable to save role: {errors}", array('{errors}' => $errors)));
}
$this->redirect('manageRoles');
}
$this->render('manageRoles', array('dataProvider' => $dataProvider, 'model' => $model, 'roles' => $arr, 'workflows' => $workflows));
}
示例11: _save
/**
* @param \Roles $role
* @param $error
* @return bool|\Roles
* @throws \Exception
*/
protected function _save(\Roles $role, &$error)
{
$current_status = $role->getStatus();
$data = $this->post('role', 'ARRAY', []);
$role->hydrate($data);
if (!isset($data['admin_access'])) {
$role->setAdminAccess(0);
}
$parentId = $this->post('role_parent', 'INT', 0);
if ($parentId == 0) {
$parent = \Roles::retrieveRoot();
} else {
$parent = \Roles::retrieveById($parentId);
if (!$parent) {
$error['parent'] = array(t('Role parent not found with id:' . $parentId));
return false;
}
}
$is_new = $role->isNew();
$role->beginTransaction();
try {
if ($is_new) {
//always save
$role->setParentId($parent->getId());
$role->setStatus($parent->getStatus());
$role->insertAsLastChildOf($parent);
//dispatch event
$this->dispatch('onCreateNewRole', new CMSBackendEvent($this, ['role' => $role]));
} else {
$currentParent = $role->getParent();
if ($parent->getId() == $role->getId()) {
//something fucked
$error['parent'] = t('Could not move to child of itself!');
}
if ($currentParent->getId() != $parent->getId()) {
//move tree
$role->moveToLastChildOf($parent);
$role->setParentId($parent->getId());
$role->setStatus($parent->getStatus());
if (!$role->save()) {
//save information first
$this->dispatch('onUpdateRole', new CMSBackendEvent($this, ['role' => $role]));
if (!$role->isValid()) {
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
}
}
} else {
//simply save information
if ($role->save()) {
//dispatch event update
$this->dispatch('onUpdateRole', new CMSBackendEvent($this, ['role' => $role]));
} else {
if (!$role->isValid()) {
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
}
}
if (!empty($error)) {
$role->rollBack();
return false;
}
}
//end simply save information
if ($current_status != $role->getStatus() && $role->getStatus() == \Roles::STATUS_INACTIVE) {
//change status to INACTIVE
$role->changeDescendantsStatus(\Roles::STATUS_INACTIVE);
}
}
if ($role->isValid()) {
$role->commit();
return $role;
}
$role->rollBack();
} catch (\Exception $e) {
$role->rollBack();
throw $e;
}
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
return false;
}
示例12: actionAjaxAddLineRole
public function actionAjaxAddLineRole()
{
if (isset($_POST['role_name'])) {
$role = new Roles();
$role->role_name = $_POST['role_name'];
$role->role_description = $_POST['role_description'];
if ($role->save()) {
echo '{"status":"success"}';
} else {
echo '{"status":"error"}';
}
}
}
示例13: actionRoleException
public function actionRoleException()
{
$model = new Roles();
$temp = Workflow::model()->findAll();
$workflows = array();
foreach ($temp as $workflow) {
$workflows[$workflow->id] = $workflow->name;
}
if (isset($_POST['Roles'])) {
$workflow = $_POST['workflow'];
$workflowName = Workflow::model()->findByPk($workflow)->name;
$stage = $_POST['workflowStages'];
$stageName = WorkflowStage::model()->findByPk($stage)->name;
$viewPermissions = $_POST['viewPermissions'];
$editPermissions = $_POST['editPermissions'];
$users = $_POST['users'];
$model->attributes = $_POST['Roles'];
$oldRole = Roles::model()->findByAttributes(array('name' => $model->name));
$model->users = "";
$model->name .= " - {$workflowName}: {$stageName}";
if ($model->save()) {
$replacement = new RoleToWorkflow();
$replacement->workflowId = $workflow;
$replacement->stageId = $stage;
$replacement->roleId = $oldRole->id;
$replacement->replacementId = $model->id;
$replacement->save();
$fields = Fields::model()->findAll();
$temp = array();
foreach ($fields as $field) {
$temp[] = $field->id;
}
$both = array_intersect($viewPermissions, $editPermissions);
$view = array_diff($viewPermissions, $editPermissions);
$neither = array_diff($temp, $viewPermissions);
foreach ($both as $field) {
$rolePerm = new RoleToPermission();
$rolePerm->roleId = $model->id;
$rolePerm->fieldId = $field;
$rolePerm->permission = 2;
$rolePerm->save();
}
foreach ($view as $field) {
$rolePerm = new RoleToPermission();
$rolePerm->roleId = $model->id;
$rolePerm->fieldId = $field;
$rolePerm->permission = 1;
$rolePerm->save();
}
foreach ($neither as $field) {
$rolePerm = new RoleToPermission();
$rolePerm->roleId = $model->id;
$rolePerm->fieldId = $field;
$rolePerm->permission = 0;
$rolePerm->save();
}
}
$this->redirect('manageRoles');
}
$this->render('roleException', array('model' => $model, 'workflows' => $workflows));
}
示例14: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Roles;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Roles']))
{
$model->attributes=$_POST['Roles'];
if($model->save())
$this->redirect(Yii::app()->createUrl('tmanage/roles'));
}
$this->render('create',array(
'model'=>$model,
));
}