kade

技術系の記事を書いていきます。

CakePHP: MySQLの正規表現検索

普通なら

select * from table where hoge regexp "fuga";

とかでhogeカラムにfugaの入った検索が出来ますがcakephpを使うと少し記法が異なります。

$conditions = array(
    "hoge REGEXP" => "fuga"
);

$params = array(
    'conditions' => $conditions,
    'order' => 'id desc',
);
$this->set('foos',$this->Foo->find('all',$params));

こんな感じでいけます。

詳解CakePHP辞典―2.0/2.1/2.2/2.3対応

詳解CakePHP辞典―2.0/2.1/2.2/2.3対応