cakephp - Search functionality not working using ID field input -
i using search plugin on https://github.com/cakedc/search. trying search records using id field only, if type in 1 on form input must show record user id 1. challenge having when specify input should id field, input field search functionality disappears on index view, unusual thing when specify different field name input field shows.
below code model
public $actsas = array('search.searchable'); public $filterargs = array( 'id' => array('type' => 'like', 'field' => 'itsupportrequest.id'), ); public function findbytags($data = array()) { $this->tagged->behaviors->attach('containable', array('autofields' => false)); $this->tagged->behaviors->attach('search.searchable'); $query = $this->tagged->getquery('all', array( 'conditions' => array('tag.name' => $data['tags']), 'fields' => array('foreign_key'), 'contain' => array('tag') )); homecoming $query; } public function orconditions($data = array()) { $filter = $data['filter']; $cond = array( 'or' => array( $this->alias . '.id like' => '%' . $filter . '%', )); homecoming $cond;
}
and here controller code.
public $components = array('search.prg'); public $presetvars = true; // using model configuration public function find() { $this->prg->commonprocess(); $this->paginate['conditions'] = $this->itsupportrequest->parsecriteria($this->passedargs); $this->set('articles', $this->paginate()); }
and in index.ctp file have code.
<?php echo $this->form->create('itsupportrequest', array( 'url' => array_merge(array('action' => 'find'), $this->params['pass']) )); echo $this->form->label('query id:') . "<br/>"; echo $this->form->input('name', array('div' => false, 'label' => false)); echo $this->form->submit(__('search'), array('div' => false)); echo $this->form->end(); ?>
thanks in advance.
you should not phone call id id hidden (because cake assumes primary key here).
either name else or manually overwrite behavior using
$this->form->input('id', array('type' => 'text'));
but go sth "search" and
$this->form->input('search', array('placeholder' => 'id for'));
and
public $filterargs = array( 'search' => array('type' => 'like', 'field' => 'itsupportrequest.id'), );
cakephp
No comments:
Post a Comment