###前提・実現したいこと
CakePHP2のブログチュートリアルの
https://book.cakephp.org/2.0/ja/tutorials-and-examples/blog-auth-example/auth.html
を実装したいのですが、うまくいきません。
###発生している問題・エラーメッセージ
http://localhost/cake/users/add で追加したユーザー名とパスワードを http://localhost/cake/users/login に入力しても、この画面のままになってしまい、 記事の投稿などが出来ません。 あと、$this->log()をしたいのですが、 具体的にどこに書いてどこから見ればいいのかがわかりません。 ```ここに言語を入力 UsersControllerのコードです。 <?php App::uses('AppController', 'Controller'); class UsersController extends AppController { //.... public function beforeFilter() { parent::beforeFilter(); // ユーザー自身による登録とログアウトを許可する $this->Auth->allow('add', 'logout'); } public function login() { if ($this->request->is('post')) { if ($this->Auth->login()) { $this->redirect($this->Auth->redirect()); } else { $this->Flash->error(__('Invalid username or password, try again')); } } } public function logout() { $this->redirect($this->Auth->logout()); } public function index() { $this->User->recursive = 0; $this->set('users', $this->paginate()); } public function view($id = null) { $this->User->id = $id; if (!$this->User->exists()) { throw new NotFoundException(__('Invalid user')); } $this->set('user', $this->User->findById($id)); } public function add() { if ($this->request->is('post')) { $this->User->create(); if ($this->User->save($this->request->data)) { $this->Flash->success(__('The user has been saved')); return $this->redirect(array('action' => 'index')); } $this->Flash->error( __('The user could not be saved. Please, try again.') ); } } public function edit($id = null) { $this->User->id = $id; if (!$this->User->exists()) { throw new NotFoundException(__('Invalid user')); } if ($this->request->is('post') || $this->request->is('put')) { if ($this->User->save($this->request->data)) { $this->Flash->success(__('The user has been saved')); return $this->redirect(array('action' => 'index')); } $this->Flash->error( __('The user could not be saved. Please, try again.') ); } else { $this->request->data = $this->User->findById($id); unset($this->request->data['User']['password']); } } public function delete($id = null) { // Prior to 2.5 use // $this->request->onlyAllow('post'); $this->request->allowMethod('post'); $this->User->id = $id; if (!$this->User->exists()) { throw new NotFoundException(__('Invalid user')); } if ($this->User->delete()) { $this->Flash->success(__('User deleted')); return $this->redirect(array('action' => 'index')); } $this->Flash->error(__('User was not deleted')); return $this->redirect(array('action' => 'index')); } } ?>
add.ctpの中身です
<!-- app/View/Users/add.ctp --> <div class="users form"> <?php echo $this->Form->create('User'); ?> <fieldset> <legend><?php echo __('Add User'); ?></legend> <?php echo $this->Form->input('username'); echo $this->Form->input('password'); echo $this->Form->input('role', array( 'options' => array('admin' => 'Admin', 'author' => 'Author') )); ?> </fieldset> <?php echo $this->Form->end(__('Submit')); ?> </div>あなたの回答
tips
プレビュー