ModelSearch::addSearchItem PHP Method

addSearchItem() public method

Add a search item.
public addSearchItem ( $key, string | array $search = '' )
$key
$search string | array
    public function addSearchItem($key, $search = '')
    {
        $this->searchItems[$key] = $search;
        if (is_array($search) && array_key_exists('default', $search) && !array_key_exists($key, $this->searchTerms)) {
            $criteria = $this->getCriteria();
            $criteria->addCondition($key . ' = ' . $search['default']);
        }
    }

Usage Example

Example #1
0
 /**
  * Sets up search on all listed elements
  */
 public function searchAll()
 {
     $searchArray = array('type' => 'compare', 'compare_to' => array());
     $searchFirst = '';
     foreach ($this->listFields as $field) {
         if (method_exists($this->model, 'get_' . $field)) {
             //we don't currently support searching on magic attributes not from the DB so continue
             continue;
         }
         if ($searchFirst === '') {
             $searchFirst = $field;
         } else {
             $searchArray['compare_to'][] = $field;
         }
     }
     $this->search->addSearchItem($searchFirst, $searchArray);
 }
All Usage Examples Of ModelSearch::addSearchItem