は、私は良いアイデアのではないと思いますが、これを行う方法は簡単です。
使用したバージョン:CakePHPのv3.4.5
テンプレート\ Users \ユーザーlogin.ctp:
<form method="post" action="<?= $this->Url->build(['controller'=>'Users', 'action' => 'login']) ?>">
<input type="text" name="id" value="">
<button type="submit">login</button>
</form>
コントローラー\ UsersController.php:
public function login()
{
if ($this->request->is('post')) {
$user = $this->Users->findById($this->request->getData()['id'])->first();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect(['controller' => 'MyController', 'action' => 'MyAction']);
}
$this->Flash->error('Id not found.');
return $this->redirect($this->referer());
}
}
いけないのAppControllerでAuthコンポーネントをロードすることを忘れますhereと記載されている権限のないユーザーのログイン方法を許可します。
これは完璧です!どうもありがとうございました。 :) – Tom