CakePHP2系です。
SearchPluginを使用しています。
検索フォームが複数あり、各フォームで検索条件を分けたいのですが、
使用しているモデルとコントローラーが同じのため(actionが違う)モデルのHoge.phpに設定している条件が全部に適応されてしまいます。
PHP
1// app/Model/Hoge.php 2 public $filterArgs = array( 3 'keyword' => array( 4 'type' => 'like', 5 'field' => array('Hoge.title', 'Video.content', 'Video.poster'), 6 'connectorAnd' => ' ', 7 'connectorOr' => '+'), 8 ); 9
上記ですと、title,content,posterカラムを検索対象としていますが、
他の同モデル・同コントローラーを使用したactionでは、Hoge.idのみを検索対象としたいです。
コントローラーは下記のように、追加で検索オプションを追加しています。
PHP
1// app/Controller/HogeController.phpのpublic action hoge_search() 2 3 $search_conditions = $this->passedArgs; 4 $search_conditions = array_merge($search_conditions, array('keyword' => $keyword)); 5 $search_option = array( 6 'hoge_status' => 0, 7 'foo_status' => 0, 8 'var_status' => 2, 9 ); 10 11 $this->Prg->commonProcess(); 12 13 $this->paginate = array( 14 'fields' => '*', 15 'conditions' => array( 16 $this->Video->parseCriteria($search_conditions), 17 $search_option 18 ), 19 'limit' => 50, 20 'order' => 'created DESC' 21 ); 22 $data = $this->paginate(); 23 $this->set('data', $data); 24
action内で、モデルに書いている$filterArgsを個別に設定はできないのでしょうか。
ご回答頂けますと幸いです。何卒よろしくお願い致します。
あなたの回答
tips
プレビュー