fromId() public static method

Initiliaze from id
public static fromId ( integer $userRoleId ) : Model
$userRoleId integer User role id
return Model
示例#1
0
文件: Model.php 项目: gotcms/gotcms
 /**
  * Get User Role
  *
  * @param boolean $forceReload Force reload
  *
  * @return \Gc\User\Role\Model
  */
 public function getRole($forceReload = false)
 {
     $role = $this->getData('role');
     if (empty($role) or !empty($forceReload)) {
         $role = Role\Model::fromId($this->getUserAclRoleId());
         $this->setData('role', $role);
     }
     return $this->getData('role');
 }
示例#2
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromFakeId()
 {
     $this->assertFalse(Model::fromId(42));
 }
示例#3
0
 /**
  * Edit role
  *
  * @return \Zend\View\Model\ViewModel|array
  */
 public function editAction()
 {
     $roleId = $this->getRouteMatch()->getParam('id');
     $roleModel = Role\Model::fromId($roleId);
     if (empty($roleModel) or $roleModel->getName() === Role\Model::PROTECTED_NAME) {
         $this->flashMessenger()->addErrorMessage("Can't edit this role");
         return $this->redirect()->toRoute('config/user/role');
     }
     $form = new RoleForm();
     $form->initPermissions($roleModel->getUserPermissions());
     $form->setAttribute('action', $this->url()->fromRoute('config/user/role/edit', array('id' => $roleId)));
     $form->loadValues($roleModel);
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost()->toArray();
         $form->setData($post);
         if ($form->isValid()) {
             $roleModel->addData($form->getInputFilter()->getValues());
             $roleModel->save();
             $this->flashMessenger()->addSuccessMessage('Role saved!');
             return $this->redirect()->toRoute('config/user/role/edit', array('id' => $roleId));
         }
         $this->flashMessenger()->addErrorMessage('Role can not saved!');
         $this->useFlashMessenger();
     }
     return array('form' => $form);
 }