【发布时间】:2021-04-30 07:09:45
【问题描述】:
每当我登录时,我都会将所有内容重定向到“welcome.php”。但是,如果我希望用户在用户页面上重定向并且管理员在管理页面上重定向。我能做些什么。 ?我已经定义了类型的用户已经只想单独重定向它们。例如。当新用户注册/注册时,用户和管理员选项就会出现。
在 UsersController.php 中
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'));
}
}
注册.php
<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>
【问题讨论】:
标签: php cakephp cakephp-4.x