本文整理汇总了PHP中App\Model\User::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP User::toArray方法的具体用法?PHP User::toArray怎么用?PHP User::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Model\User
的用法示例。
在下文中一共展示了User::toArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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');
}
}
示例3: user
/**
* Show user.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return \Psr\Http\Message\MessageInterface
*/
public function user(ServerRequestInterface $request, ResponseInterface $response)
{
$response->write($this->json->render($this->user->toArray()));
return $this->json->response($response);
}