読者です 読者をやめる 読者になる 読者になる

メモ: CakePHP find() での条件指定バリエーション

http://my.opera.com/sizuhiko/blog/2008/06/09/cakephp-1-2-rc1-find
http://cakephp.jp/modules/newbb/viewtopic.php?topic_id=1262&forum=6&post_id=2605#

<?php

//like ...
$conditions = array("Post.title LIKE" => "%post%");

// between
$conditions = array("Post.date BETWEEN ? AND ?" => array("2008-1-1", "2009-1-1"));

// like
$conditions = array("Post.title LIKE ?" => array("%post%"));

// in(...)
$conditions = array("Post.id" => array(1,2,3,4,5));

$this->Post->find($conditions);
?>


そして、
http://spiral-stair.blogspot.com/2007/09/cakephpfindor.html

<?php
$conditions = array(
                   'Model' => array(
                                    'id' => 1,
                                    'or' => array(
                                                  array('user' => 'hogehoge'),
                                                  array('user' => 'mogumogu')
                                                 )
                                   )
                   );
$this->Model->find($conditions);
?>
WHERE (`id` = 1) AND ((`user` = hogehoge) OR (`user` = mogumogu))
<?php
$conditions = array(
                   'Model' => array(
                                    'id' => 1,
                                    'or' => array(
                                                  array(
                                                        'user' => 'hogehoge',
                                                        'password' => 'hagehage'
                                                       ),
                                                  array(
                                                        'user' => 'mogumogu',
                                                        'password' => 'magumagu'
                                                       )
                                                 )
                                   )
                   );
$this->Model->find($conditions);
?>
WHERE (`id` = 1) AND (((`user` = hogehoge) AND (`password` = hagehage)) OR ((`user` = mogumogu) AND (`password` = magumagu)))