コード例 #1
0
 /**
  * Edit action.
  *
  * @return void
  *
  * @Route("/edit/{id:[0-9]+}", methods={"GET", "POST"}, name="admin-user-edit")
  */
 public function editAction($id = 0)
 {
     $formData = [];
     $message = '';
     if ($this->request->hasPost('fsubmit')) {
         if ($this->security->checkToken()) {
             $formData = array_merge($formData, $this->request->getPost());
             $myUser = UserModel::findFirst(['id = :id:', 'bind' => ['id' => (int) $id]]);
             $myUser->assign($formData);
             if ($myUser->update()) {
                 $this->flash->success(str_replace('###name###', $myUser->name, $this->lang->_('message-update-user-success')));
             } else {
                 foreach ($myUser->getMessages() as $msg) {
                     $message .= $this->lang->_($msg->getMessage()) . '<br />';
                 }
                 $this->flash->error($message);
             }
         } else {
             $this->flash->error($this->lang->_('default.message-csrf-protected'));
         }
     }
     /**
      * Find user by id
      */
     $myUser = UserModel::findFirst(['id = :id:', 'bind' => ['id' => (int) $id]]);
     $formData = $myUser->toArray();
     $formData['thumbnailImage'] = $myUser->getThumbnailImage();
     $this->bc->add($this->lang->_('title-index'), 'admin/user');
     $this->bc->add($this->lang->_('title-create'), '');
     $this->view->setVars(['formData' => $formData, 'bc' => $this->bc->generate(), 'statusList' => UserModel::getStatusList(), 'roleList' => UserModel::getRoleList()]);
 }