I am in process of creating a search function for my site. It has
three search parameters. I have worked it this way.
The search functions properly with pagination. The problem is small; I
am not able to identify how to set optional field. When a user passes
all the parameters for search there is no error message; but if one of
those is left blank; I get an error stating "Undefined variable:
medicine".
My controller search function code is as under.
if (!empty($this->passedArgs)) {
if(isset($this->passedArgs['Article.search'])) {
$keyword = $this->passedArgs['Article.search'];
$this->data['Article']['search'] = $keyword;
$this->set('keyword');
}
if(isset($this->passedArgs['Article.author_id'])) {
$author = $this->passedArgs['Article.author_id'];
$this->data['Article']['author_id'] = $author;
$this->set('author');
}
if(isset($this->passedArgs['Article.area'])) {
$medicine = $this->passedArgs['Article.medicine'];
$this->data['Article']['medicine'] = $medicine;
$this->set('area');
}
$conditions = array(
"Article.author_id LIKE" => "%$author%",
"Article.medicine LIKE" => "%$medicine%",
"or" => array(
"Article.medication LIKE" =>
"%$keyword%",
"Article.description LIKE" =>
"%$keyword%"
))
;
} else {
$this->redirect(array('controller'=>'Articles','action'=>'search'));
}
$articles = $this->paginate('Article', $conditions);
$authors = $this->Article->Author->find('list', array('fields' =>
array('author_name'),
'conditions' => array('Author.status_id' => 1)));
$this->set(compact('authors', 'articles'));
$this->layout = 'resultlist';
$this->set('title_for_layout', 'Search Result');
}
I think, I am not able to set up optional field properly. So, please
help us with your valuable suggestion.
Thanks in advance.
Regards.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php