0
作爲管理員,我想以另一身份訪問後臺作爲普通用戶。CakePHP3:如何以其他用戶身份登錄
所以我選擇列表中的用戶並將其提交給我的控制器。
我試着下面的代碼,但我從來沒有訪問目標URL,我收到HTTP代碼302,如果我試圖訪問的URL,而無需登錄任何用戶。
什麼問題?
$id = $this->Auth->user('id');
$user = $this->Users->get($this->Auth->user('id'));
if (($user['role'] == 'admin') && (!empty($this->request->data))) {
$id = $this->request->data['id'];
if (!$this->Users->exists($id)) {
throw new NotFoundException(__('Invalid User'));
}
$user = $this->Users->findById($id);
$this->Auth->setUser($user->toArray());
return $this->redirect([
'controller' => 'Owners',
'action' => 'account',
'prefix' => 'pros'
]);
}