CakePHP3(3.0.0-alpha1)のブログチュートリアルで記事にコメント機能を追加する3
①ArticlesControllerにactionを追加
addをベースにしながら、色々試したかったのでaddの流れから少しだけ変更してある。
public function comment() { $this->loadModel('Comments'); $comment = $this->Comments->newEntity($this->request->data); if ($this->request->is('post')) { if ($this->Comments->save($comment)) { $this->Flash->success(__('Your comment has been saved.')); //return $this->redirect(['action' => 'index']); }else{ $this->Flash->error(__('Unable to add your comment.')); } } return $this->redirect('/articles/view/'.$this->request->data['article_id']); }
前の記事でも$this->loadModel('Comments');でモデルを読み込むと書いたけれど、pdf版のドキュメントを見ると
Note: CakePHP merges the following variables from the AppController into your application’s controllers:
・$components
・$helpers
・$uses
と書いてあり、$usesだけリンクがない状態。この後のバージョンで追加されるのかも?