###FriendsOfCake/search を使用して検索を行いたい
現在、CAKEPHP3を習得するために勉強をしております。
CAKEPHPのチュートリアルはブログまで行いました。
そんな中で、様々な場所で検索をさせるのにFriendsOfCake/search
プラグインを使用して実装しようと考えております。
プラグインの導入はINDEX(一覧表示ページ)完了し、検索をかけたところ問題ありませんでした。
###発生している問題・エラーメッセージ
FriendsOfCake/searchプラグインを使用することにより
BAKEで作成したaddでは新規追加できない。
BAKEで作成したeditでは編集した値が更新されない。
BAKEで作成したdeleteでは削除できず。
###該当のソースコード
* Add method * * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. */ public function add() { $user = $this->Users->newEntity(); if ($this->request->is('post')) { $user = $this->Users->patchEntity($user, $this->request->data); if ($this->Users->save($user)) { $this->Flash->success(__('The user has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The user could not be saved. Please, try again.')); } } $companies = $this->Users->Companies->find('list', ['limit' => 200]); $this->set(compact('user', 'companies')); $this->set('_serialize', ['user']); } /** * Edit method * * @param string|null $id User id. * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException 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->data); if ($this->Users->save($user)) { $this->Flash->success(__('The user has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The user could not be saved. Please, try again.')); } } $companies = $this->Users->Companies->find('list', ['limit' => 200]); $this->set(compact('user', 'companies')); $this->set('_serialize', ['user']); } /** * Delete method * * @param string|null $id User id. * @return \Cake\Network\Response|null 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']); }
###試したこと
URLを見ると、パラメーターがわたっているのでpostではなくgetで飛ばしているのかなと推測し、各部位のコントローラーをpost からgetに変更したところ、add,deleteは動作したのですが、editのみ更新されない様子でした。
editの
if
1 $user = $this->Users->patchEntity($user, $this->request->data);
の部分を修正すればいいのかなと思いますが、果たしてあっているのかがわからなくなってしまっております。
###補足情報(言語/FW/ツール等のバージョンなど)
cakephp3
###indexだけにプラグインを充てることは可能なのでしょうか?
現在コントローラーに
public
1 { 2 parent::initialize(); 3 $this->loadComponent('Search.Prg'); 4 } ``` 5としてあるのですが、適応範囲をindexのみにしそのほかのアクションに対しては反応しないようにできれば一番いいのかなと思いますが可能なのでしょうか。 6 7 8 9 10初歩的なご質問で大変恐縮ではありますが、何卒お教えいただけましたら幸いです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/04/29 04:23
2016/05/02 09:45