当前位置: 首页>>代码示例>>PHP>>正文


PHP Role::save方法代码示例

本文整理汇总了PHP中Role::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::save方法的具体用法?PHP Role::save怎么用?PHP Role::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Role的用法示例。


在下文中一共展示了Role::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postCreate

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate()
 {
     $rules = array('name' => 'required|alpha_dash|unique:roles,name', 'permissions' => 'required');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Get the inputs, with some exceptions
         $inputs = Input::except('csrf_token');
         $this->role->name = $inputs['name'];
         $this->role->save();
         // Save permissions
         $this->role->savePermissions($inputs['permissions']);
         // Was the role created?
         if ($this->role->id) {
             // Redirect to the new role page
             return Redirect::to('admin/roles/' . $this->role->id . '/edit')->with('success', Lang::get('admin/roles/messages.create.success'));
         }
         // Redirect to the new role page
         return Redirect::to('admin/roles/create')->with('error', Lang::get('admin/roles/messages.create.error'));
         // Redirect to the role create page
         return Redirect::to('admin/roles/create')->withInput()->with('error', Lang::get('admin/roles/messages.' . $error));
     }
     // Form validation failed
     return Redirect::to('admin/roles/create')->withInput()->withErrors($validator);
 }
开发者ID:koanreview,项目名称:laravel-admin-template,代码行数:31,代码来源:AdminRolesController.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Declare the rules for the form validation
     $rules = array('name' => 'required');
     $getPermissions = Input::get('permissions');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Get the inputs, with some exceptions
         $inputs = Input::except('csrf_token');
         $this->role->name = $inputs['name'];
         $this->role->save();
         // Save permissions
         $perms = $this->permission->get();
         if (count($perms)) {
             if (isset($getPermissions)) {
                 $this->role->perms()->sync($this->permission->preparePermissionsForSave($getPermissions));
             }
         }
         // Was the role created?
         if ($this->role->id) {
             // Redirect to the new role page
             return Redirect::to('admin/roles/' . $this->role->id . '/edit')->with('success', Lang::get('admin/roles/messages.create.success'));
         }
         // Redirect to the new role page
         return Redirect::to('admin/roles/create')->with('error', Lang::get('admin/roles/messages.create.error'));
         // Redirect to the role create page
         return Redirect::to('admin/roles/create')->withInput()->with('error', Lang::get('admin/roles/messages.' . $error));
     }
     // Form validation failed
     return Redirect::to('admin/roles/create')->withInput()->withErrors($validator);
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:38,代码来源:AdminRolesController.php

示例3: setUp

 public function setUp()
 {
     parent::setUp();
     $this->role = Role::getNewInstance('__testrole__');
     $this->role->save();
     $this->userGroup = UserGroup::getNewInstance('Any random group name');
     $this->userGroup->save();
 }
开发者ID:saiber,项目名称:livecart,代码行数:8,代码来源:AccessControlAssociationTest.php

示例4: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Validate the inputs
     $rules = array('name' => 'required|alpha_dash|unique:roles,name', 'description' => 'required');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Get the inputs, with some exceptions
         $inputs = Input::except('csrf_token');
         $this->role->name = $inputs['name'];
         $this->role->description = $inputs['description'];
         $this->role->save($rules);
         if ($this->role->id) {
             // Save permissions
             $this->role->perms()->sync($this->permission->preparePermissionsForSave($inputs['permissions']));
             // Redirect to the new role page
             return Redirect::to('admin/roles/' . $this->role->id . '/edit')->with('success', Lang::get('admin/role/messages.create.success'));
         } else {
             // Redirect to the role create page
             //var_dump($this->role);
             return Redirect::to('admin/roles/create')->with('error', Lang::get('admin/role/messages.create.error'));
         }
     } else {
         // Form validation failed
         return Redirect::to('admin/roles/create')->withInput()->withErrors($validator);
     }
 }
开发者ID:ehumps,项目名称:rendezview,代码行数:33,代码来源:AdminRolesController.php

示例5: run

 public function run()
 {
     $user = new User();
     $user->email = 'danny_kent@mail.ru';
     $user->username = 'danny-admin';
     $user->password = Hash::make('secret');
     $user->password_confirmation = $user->password;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->email . '" <' . $user->email . '>');
     }
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $user = new User();
     $user->email = 'somovlife@gmail.com';
     $user->username = 'ivan-admin';
     $user->password = Hash::make('secret');
     $user->password_confirmation = $user->password;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->email . '" <' . $user->email . '>');
     }
     $user = User::where('username', $user->username)->firstOrFail();
     $user->attachRole($admin);
 }
开发者ID:VerticalHorizon,项目名称:Bumagi,代码行数:32,代码来源:UsersTableSeeder.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), Config::get('validator.admin.role'));
     if ($validator->passes()) {
         $role = new Role();
         $role->name = Input::get('name');
         $role->deletable = 1;
         // Was the blog post created?
         if ($role->save()) {
             //Set all permission to deny
             $resources = Resource::where('in_admin_ui', '=', 1)->get();
             $data = array();
             foreach ($resources as $resource) {
                 foreach (Action::all() as $action) {
                     $data[] = array('role_id' => $role->id, 'type' => 'deny', 'action_id' => $action->id, 'resource_id' => $resource->id);
                 }
             }
             DB::table('permissions')->insert($data);
             //track user
             parent::track('create', 'Role', $role->id);
             return Redirect::to('admin/role_permission')->with('success', Lang::get('admin.role_save_success'));
         }
         // Redirect to the blog post create role
         return Redirect::to('admin/role/create')->with('error', Lang::get('admin.role_save_fail'));
     }
     // Form validation failed
     return Redirect::to('admin/role/create')->withInput()->withErrors($validator);
 }
开发者ID:Metrakit,项目名称:dynamix,代码行数:33,代码来源:AdminRoleController.php

示例7: run

 public function run()
 {
     //DB::table('roles')->delete();
     DB::statement('ALTER TABLE permissions AUTO_INCREMENT = 1');
     $adminRole = new Role();
     $adminRole->name = 'admin';
     $adminRole->save();
     $user = User::where('username', '=', 'admin')->first();
     $user->attachRole($adminRole);
     $BrokerRole = new Role();
     $BrokerRole->name = 'broker';
     $BrokerRole->save();
     $user = User::where('username', '=', 'broker')->first();
     $user->attachRole($BrokerRole);
     $campusRole = new Role();
     $campusRole->name = 'campus';
     $campusRole->save();
     $user = User::where('username', '=', 'campus')->first();
     $user->attachRole($campusRole);
     $communityRole = new Role();
     $communityRole->name = 'community';
     $communityRole->save();
     $user = User::where('username', '=', 'community')->first();
     $user->attachRole($communityRole);
 }
开发者ID:bktz,项目名称:cup,代码行数:25,代码来源:RolesTableSeeder.php

示例8: run

 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     // DB::table('departments')->truncate();
     //    $department = new Department;
     //    $department->department_desc = 'ADMIN';
     //    $department->save();
     DB::table('roles')->truncate();
     $role = new Role();
     $role->name = 'ADMINISTRATOR';
     $role->save();
     DB::table('users')->truncate();
     DB::table('assigned_roles')->truncate();
     $user = new User();
     $user->username = 'admin';
     $user->email = 'admin@prs.com';
     $user->password = '031988';
     $user->password_confirmation = '031988';
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     // $user->confirmed = 1;
     // $user->active = 1;
     // $user->department_id = $department->id;
     $user->save();
     $user->roles()->attach($role->id);
     // id only
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
开发者ID:jcyanga28,项目名称:project-reference,代码行数:27,代码来源:UserTableSeeder.php

示例9: setupDatabases

 public function setupDatabases()
 {
     $name = $this->call('migrate', array('--path' => 'app/database/migrations/setup/'));
     $name = $this->call('migrate');
     // create the roles
     $roles = ['Admin', 'Writer', 'Reader'];
     foreach ($roles as $r) {
         $role = Role::whereName($r)->first();
         if ($role == null) {
             $role = new Role();
             $role->name = $r;
             $role->display_name = $r;
             $role->save();
             $this->info("{$role->id} Creating Role:{$r}");
         }
     }
     foreach (User::all() as $u) {
         $this->info("{$u->id} : user: {$u->username}");
     }
     // add core assets
     $m = Asset::findFromTag('missing-user-image');
     if ($m == NULL) {
         $m = new Asset();
         $m->path = "assets/content/uploads";
         $m->saveLocalFile(public_path('assets/content/common/missing/profile-default.png'), 'profile-default.png');
         $m->tag = 'missing-user-image';
         $m->shared = 1;
         $m->type = Asset::ASSET_TYPE_IMAGE;
         $m->save();
     }
     $this->comment("****\tAll Databases for Halp have been setup :-) \t****");
     return;
 }
开发者ID:vanderlin,项目名称:halp,代码行数:33,代码来源:CreateDatabases.php

示例10:

 /**
  * Set permission value
  *
  * @param void
  * @return null
  */
 function set_permission_value()
 {
     if ($this->active_role->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($this->active_role->getType() == ROLE_TYPE_PROJECT) {
         $this->httpError(HTTP_ERR_INVALID_PROPERTIES);
     }
     // if
     if ($this->request->isSubmitted() && $this->request->isAsyncCall()) {
         $permission_name = $this->request->get('permission_name');
         if ($permission_name) {
             $this->active_role->setPermissionValue($permission_name, $this->request->post('value'));
             $save = $this->active_role->save();
             if ($save && !is_error($save)) {
                 $this->httpOk();
             }
             // if
         }
         // if
         $this->httpError(HTTP_ERR_OPERATION_FAILED);
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:33,代码来源:RolesAdminController.class.php

示例11: testAddingUserToRole

 public function testAddingUserToRole()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $role = new Role();
     $role->name = 'myRole';
     $role->validate();
     $saved = $role->save();
     $this->assertTrue($saved);
     $benny = User::getByUsername('benny');
     //Add the role to benny
     $benny->role = $role;
     $saved = $benny->save();
     $this->assertTrue($saved);
     $roleId = $role->id;
     unset($role);
     $role = Role::getById($roleId);
     $this->assertEquals(1, $role->users->count());
     $this->assertTrue($role->users[0]->isSame($benny));
     //Now try adding billy to the role but from the other side, from the role side.
     $billy = User::getByUsername('billy');
     $role->users->add($billy);
     $saved = $role->save();
     $this->assertTrue($saved);
     $billy->forget();
     //need to forget billy otherwise it won't pick up the change. i tried unset(), test fails
     $billy = User::getByUsername('billy');
     $this->assertTrue($billy->role->id > 0);
     $this->assertTrue($billy->role->isSame($role));
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:29,代码来源:RoleTest.php

示例12: doSave

 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aRole !== null) {
             if ($this->aRole->isModified() || $this->aRole->isNew()) {
                 $affectedRows += $this->aRole->save($con);
             }
             $this->setRole($this->aRole);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = TeamNotePeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setNew(false);
             } else {
                 $affectedRows += TeamNotePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
开发者ID:yasirgit,项目名称:afids,代码行数:46,代码来源:BaseTeamNote.php

示例13: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //1.  Create Independent Sponsor role
     $sponsorRole = Role::where('name', '=', 'Independent Sponsor')->first();
     if (!$sponsorRole) {
         $sponsorRole = new Role();
         $sponsorRole->name = "Independent Sponsor";
         $sponsorRole->save();
         $this->info("Independent Sponsor role created.");
     } else {
         $this->info("Independent Sponsor role exists.");
     }
     //2. Add Independent Sponsor role to all Admins
     $adminRole = Role::where('name', 'Admin')->first();
     $admins = $adminRole->users()->get();
     foreach ($admins as $admin) {
         $this->info('--------------------------------------------------');
         if ($admin->hasRole($sponsorRole->name)) {
             $this->info($admin->email . " already set as Independent Sponsor");
         } else {
             $admin->attachRole($sponsorRole);
             $this->info($admin->email . " set as " . $sponsorRole->name);
         }
         //3.  Remove Admin role from non-admin users
         $stayAdmin = strtolower(trim($this->ask("Keep " . $admin->email . " as an Admin? (yes/no)")));
         if ($stayAdmin != 'yes') {
             $admin->detachRole($adminRole);
             $this->info("Removed Admin role from " . $admin->email);
         } else {
             $this->info($admin->email . " still set as an Admin.");
         }
     }
 }
开发者ID:DCgov,项目名称:dc-madison,代码行数:38,代码来源:dbUpdateGroups.php

示例14: executeProcessNewOrgForm

 public function executeProcessNewOrgForm(sfWebRequest $request)
 {
     $f = $request->getParameter("organization");
     $p = Doctrine::getTable('Principal')->findOneByFedid($this->getUser()->getUsername());
     $o = new Organization();
     $o->setName($f["name"]);
     $o->setDescription($f["description"]);
     $o->setCreatedAt(date('Y-m-d H:i:s'));
     $o->save();
     $op = new OrganizationPrincipal();
     $op->setOrganization($o);
     $op->setPrincipal($p);
     $op->save();
     $i = new Invitation();
     $i->setEmail($p->getEmail());
     $i->setOrganization($o);
     $i->setUuid('1');
     $i->setCreatedAt(date('Y-m-d H:i:s'));
     $i->setAcceptAt(date('Y-m-d H:i:s'));
     $i->setCounter(1);
     $i->setInviter($p);
     $i->setPrincipal($p);
     $i->setStatus("accepted");
     $i->save();
     $r = new Role();
     $r->setName($f["role_name"]);
     $r->setOrganization($o);
     $r->setShoworder(0);
     $r->save();
     $o->setDefaultRoleId($r->getId());
     $o->save();
     $this->redirect("show/index?id=" . $o->getId());
 }
开发者ID:br00k,项目名称:yavom,代码行数:33,代码来源:actions.class.php

示例15: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if ($this->argument('name')) {
         $name = trim($this->argument('name'));
         $role = Role::where('name', '=', $name)->first();
         if ($role) {
             $this->info("Role '{$name}' already exists.");
             exit;
         }
         $role = new Role();
         $role->name = $name;
         $role->save();
         $this->info('Role saved successfully.');
     } else {
         $roles = Role::all();
         $this->info('Existing Roles:');
         foreach ($roles as $role) {
             $this->info($role->name);
         }
         $continue = $this->ask("Would you still like to add a new role? (yes/no)");
         if ('yes' === trim(strtolower($continue))) {
             $name = $this->ask("What's the new role's name?");
             $role = new Role();
             $role->name = trim($name);
             $role->save();
             $this->info('Role saved successfully.');
         }
     }
 }
开发者ID:krues8dr,项目名称:madison,代码行数:34,代码来源:CreateRole.php


注:本文中的Role::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。