예제 #1
0
 public function searchAction($keyword)
 {
     $terms = explode(" ", $keyword);
     $termCounter = 0;
     $conditions = '';
     $bind = array();
     foreach ($terms as $term) {
         if ($conditions != '') {
             $conditions .= ' AND ';
         }
         $termCounter++;
         $conditions .= ' (name like ?' . $termCounter . ' OR builder like ?' . $termCounter . ') ';
         $bind[$termCounter] = '%' . $term . '%';
     }
     $data = Estate::find(array('conditions' => $conditions, 'bind' => $bind, 'limit' => 15));
     $json = array();
     foreach ($data as $row) {
         $json[] = $row->getDataAsArray();
     }
     echo json_encode($json);
 }