在cakephp中,如何将用户重定向到用户页面,将管理员重定向到管理员页面
无论何时登录,我都会将所有内容重定向到“welcome.php”。但若我想让用户在用户页面上重定向,让管理员在管理员页面上重定向。我能做什么?我已经定义了不同类型的用户,只是想分别重定向它们。例如,当新用户获得注册/注册时,用户和管理员选项就存在了 在UsersController.php中在cakephp中,如何将用户重定向到用户页面,将管理员重定向到管理员页面,php,cakephp,cakephp-4.x,Php,Cakephp,Cakephp 4.x,无论何时登录,我都会将所有内容重定向到“welcome.php”。但若我想让用户在用户页面上重定向,让管理员在管理员页面上重定向。我能做什么?我已经定义了不同类型的用户,只是想分别重定向它们。例如,当新用户获得注册/注册时,用户和管理员选项就存在了 在UsersController.php中 public function login() { $this->viewBuilder()->setLayout('login'); $this->request-
public function login()
{
$this->viewBuilder()->setLayout('login');
$this->request->allowMethod(['get', 'post']);
$result = $this->Authentication->getResult();
if ($result->isValid()) {
$redirect = $this->request->getQuery('redirect', [
'controller' => 'Users',
'action' => 'welcome',
]);
return $this->redirect($redirect);
}
if ($this->request->is('post') && !$result->isValid()) {
$this->Flash->error(__('Invalid username or password'));
}
}
signup.php
<div class="mb-3" id="div2">
<label for="utype" class="text-gray-600 mb-2 ">
Usertype</label>
<div class="form-check ">
<label class="radio-inline">
<input type="radio" name="utype" value="admin"
class=" px-3 py-2 border border-gray-300 rounded-md
" />;
Admin </label>
<label class="radio-inline">
<input type="radio" name="utype" value="user"
class="px-3 py-2 border border-gray-300 rounded-md"
checked/>;
User </label>
</div>
</div>
用户类型
;
管理
;
使用者
如果结果有效,请使用$this->Authentication->getIdentity()
获取登录用户的详细信息,并基于该信息设置$redirect
。它正是我想要的$uid=$this->Auth->user('your_字段');。