前提・実現したいこと
Cakephp3.7にて、
クエリビルダのwhere句内の条件に、
事前にforeachで加工した条件(文字列)を渡したいのですが、
上手くいきません。
ただ、渡している条件をデバッグさせ、
それを直接クエリビルダの中に入れてあげると
問題なくデータベースから抽出されることから、
文字列としては問題ないのかと思われます。
該当のソースコード
$stop_index = count($search['small_tag']); $condition = ''; foreach ($search['small_tag'] as $ksmall_tag => $vsmall_tag) { if(empty($condition)){ $condition .= "'OR' => [['Fruits.small_tag LIKE' => '%'.'".$vsmall_tag."'.'%'],"; }else{ if($stop_index == $ksmall_tag + 1){// $condition .= "['Fruits.small_tag LIKE' => '%'.'".$vsmall_tag."'.'%']]"; }else{ $condition .= "['Fruits.small_tag LIKE' => '%'.'".$vsmall_tag."'.'%'],"; } } } //$conditionをデバッグさせた一例です //'OR' => [['Fruits.small_tag LIKE' => '%'.'sweet'.'%'],['Fruits.small_tag LIKE' => '%'.'yellow'.'%']] $counts = $this->Fruits->find()->where( [ 'Fruits.tag' => "'".$search['tag']."'", $condition //←ここに渡したい。 ] )->count();
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。