PHP
1//HogesController.php 2$column01 = $this->Functions->_SearchCheckBox($this->request->data('column01'),'name','column01');
PHP
1//HogesComponent.php 2 public function _SearchCheckBox($array_value,$name,$column){ 3 $CheckBox = Configure::read('CheckBox');//配列 4 $hoges = $this->Hoges->find(); 5 $hoges->where(function ($exp, $q) use ($array_value) { 6 if (is_array($array_value) && count($array_value) > 0) { 7 $i = 0; 8 foreach ($array_value as $key) { 9 if($i == 0){ 10 $orConditions = $exp->or_([$column => $CheckBox[$name][$key]]); 11 }else{ 12 $orConditions->eq($column,$CheckBox[$name][$key]); 13 } 14 $i++; 15 } 16 } 17 18 return $exp 19 ->add($orConditions); 20 }); 21 }
PHP
1//エラー 2Call to a member function find() on null
######知りたいこと
$hoges = $this->Hoges->find();
コンポーネントでfind()が使えるようにしたいです。
######補足
検索でチェックボックスの項目が多いので、関数でまとめようとしました。
関数を書く場所が間違っていますか?何か読み込めば今のまま使えるかと
思うのですが、、それもどうなんでしょう。
チェックボックスの項目の度に
以下を書いている状態なので、どうにかしたいと試みております。
PHP
1//HogesController.php 2$column01 = $this->Functions->SearchCheckBox($this->request->data('column01'),'name');//配列 3 $hoges = $this->Hoges->find(); 4 $hoges->where(function ($exp, $q) use ($column01) { 5 if (is_array($column01) && count($column01) > 0) { 6 $i = 0; 7 foreach ($column01 as $key => $value) { 8 if($i == 0){ 9 $orConditions = $exp->or_(['column01' => $value]); 10 }else{ 11 $orConditions->eq('column01',$value); 12 } 13 $i++; 14 } 15 } 16 17 return $exp 18 ->add($orConditions); 19 });
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/27 03:51