Ejemplo n.º 1
0
 /**
  * Search the record for the Select2 JQuery Object by ajax
  * @return json
  */
 public function searchAction()
 {
     if ($this->getRequest()->isXmlHttpRequest()) {
         $term = $this->getParam('term');
         $id = $this->getParam('id');
         if (!empty($term)) {
             $term = "%{$term}%";
             $records = Invoices::findbyCustomFields("formatted_number LIKE ? OR number LIKE ?", array($term, $term));
             die(json_encode($records));
         }
         if (!empty($id)) {
             $records = Invoices::find($id);
             if ($records) {
                 $records = $records->toArray();
             }
             die(json_encode(array($records)));
         }
         $records = Invoices::getAll();
         die(json_encode($records));
     } else {
         die;
     }
 }