當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::getById方法代碼示例

本文整理匯總了PHP中App\Model\User::getById方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::getById方法的具體用法?PHP User::getById怎麽用?PHP User::getById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在App\Model\User的用法示例。


在下文中一共展示了User::getById方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: profile

 /**
  * Profile action method
  *
  * @return void
  */
 public function profile()
 {
     $this->prepareView('profile.phtml');
     $this->view->title = 'My Profile';
     $user = new Model\User();
     $user->getById($this->sess->user->id);
     $this->view->form = new Form\Profile($this->application->config()['forms']['App\\Form\\Profile']);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray());
     if ($this->request->isPost()) {
         $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $user = new Model\User();
             $user->update($this->view->form->getFields(), $this->sess);
             $this->view->id = $user->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect('/profile');
         }
     }
     $this->send();
 }
開發者ID:popphp,項目名稱:pop-bootstrap,代碼行數:26,代碼來源:IndexController.php

示例2: edit

 /**
  * Edit action method
  *
  * @return void
  */
 public function edit($id)
 {
     $user = new Model\User();
     $user->getById($id);
     if (!isset($user->id)) {
         $this->redirect('/users');
     }
     if ($this->services['acl']->isAllowed($this->sess->user->role, 'users-of-role-' . $user->role_id, 'edit')) {
         $this->prepareView('users/edit.phtml');
         $this->view->title = 'Edit User';
         $this->view->username = $user->username;
         $role = new Model\Role();
         $roles = $role->getAll();
         $roleValues = [];
         foreach ($roles as $r) {
             $roleValues[$r->id] = $r->name;
         }
         $fields = $this->application->config()['forms']['App\\Form\\User'];
         $fields[1]['username']['attributes']['onkeyup'] = 'pop.changeTitle(this.value);';
         $fields[1]['password1']['required'] = false;
         $fields[1]['password2']['required'] = false;
         $fields[0]['clear_logins']['value'][1] = $user->total_logins . ' Login' . ($user->total_logins == 1 ? '' : 's');
         $fields[0]['role_id']['type'] = 'select';
         $fields[0]['role_id']['label'] = 'Role';
         $fields[0]['role_id']['value'] = $roleValues;
         $fields[0]['role_id']['marked'] = $user->role_id;
         $this->view->form = new Form\User($fields);
         $this->view->form->addFilter('strip_tags', null, 'textarea')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray());
         if ($this->request->isPost()) {
             $this->view->form->addFilter('strip_tags', null, 'textarea')->setFieldValues($this->request->getPost());
             if ($this->view->form->isValid()) {
                 $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
                 $user = new Model\User();
                 $user->update($this->view->form->getFields(), $this->application->config()['application_title'], $this->sess);
                 $this->view->id = $user->id;
                 $this->sess->setRequestValue('saved', true);
                 $this->redirect('/users/edit/' . $user->id);
             }
         }
         $this->send();
     } else {
         $this->redirect('/users');
     }
 }
開發者ID:popphp,項目名稱:pop-bootstrap,代碼行數:49,代碼來源:IndexController.php


注:本文中的App\Model\User::getById方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。