![]
下記のサイトを参考にして
リンク内容
こちらのサイトで、ログインページから、ログインするのですが、必ずエラーになります。
Mysqlには、入力されております。
このページから、別のページにいこうとすると、(例)caketest/admin/posts
The requested URL /admin/users/login was not found on this server.
と同じエラーがでます。
ログインページとCakephpのメイン画面は表示されるので、問題点がわからず、困ってます。
MacOS Catalinaに
MAMPのPHP 7.3.11
Cakephp4.2.3
Composer version 2.0.9 2021-01-27
apacheは2です。
どなたか、アドバイスいただけたらありがたいです。
UsersController.php
declare(strict_types=1); namespace App\Controller\Admin; use App\Controller\Admin\AdminController; /** * Users Controller * * @property \App\Model\Table\UsersTable $Users * @method \App\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = []) */ class UsersController extends AdminController { public function beforeFilter(\Cake\Event\EventInterface $event) { parent::beforeFilter($event); // ログインページは認証しなくてもアクセスできる $this->Authentication->addUnauthenticatedActions(['login']); } /** * Index method * * @return \Cake\Http\Response|null|void Renders view */ public function index() { $users = $this->paginate($this->Users); $this->set(compact('users')); } /** * View method * * @param string|null $id User id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function view($id = null) { $user = $this->Users->get($id, [ 'contain' => [], ]); $this->set(compact('user')); } /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ public function add() { $user = $this->Users->newEmptyEntity(); if ($this->request->is('post')) { $user = $this->Users->patchEntity($user, $this->request->getData()); if ($this->Users->save($user)) { $this->Flash->success(__('The user has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('The user could not be saved. Please, try again.')); } $this->set(compact('user')); } /** * Edit method * * @param string|null $id User id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function edit($id = null) { $user = $this->Users->get($id, [ 'contain' => [], ]); if ($this->request->is(['patch', 'post', 'put'])) { $user = $this->Users->patchEntity($user, $this->request->getData()); if ($this->Users->save($user)) { $this->Flash->success(__('The user has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('The user could not be saved. Please, try again.')); } $this->set(compact('user')); } /** * Delete method * * @param string|null $id User id. * @return \Cake\Http\Response|null|void Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $user = $this->Users->get($id); if ($this->Users->delete($user)) { $this->Flash->success(__('The user has been deleted.')); } else { $this->Flash->error(__('The user could not be deleted. Please, try again.')); } return $this->redirect(['action' => 'index']); } public function login() { $this->request->allowMethod(['get', 'post']); $result = $this->Authentication->getResult(); // ログインしている場合はリダイレクト if ($result->isValid()) { return $this->redirect('/admin'); } // 認証失敗した場合は、エラーを表示します if ($this->request->is('post') && !$result->isValid()) { $this->Flash->error('ユーザー名かパスワードが正しくありません。'); } } public function logout() { $result = $this->Authentication->getResult(); // ログインした場合はリダイレクト if ($result->isValid()) { $this->Authentication->logout(); return $this->redirect(['controller' => 'Users', 'action' => 'login']); } } }
あなたの回答
tips
プレビュー