Prev | Current Page 227 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

As Places follows the MVC pattern, the searching takes place in the
SearchController::indexAction() function and the display of the search results is separated into the
associated view file, views/scripts/search/index.phtml. Let??™s look at the controller first.
Processing a search request in the controller
This function performs the search and assigns the results to the view. It also validates and filters the user??™s
input to ensure that we don??™t accidentally introduce cross-site security holes. The controller action is shown in
Listing 8.11.
Listing 8.11: Filtering and Validation for the search form
public function indexAction()
{
$this->view->title = 'Search Results';
$filters = array('q' => array('StringTrim' , 'StripTags')); 1
$validators = array('q' => array('presence' => 'required')); 2
$input = new Zend_Filter_Input($filters, $validators, $_GET);
if ($input->isValid()) { 3
$this->view->messages = '';
$q = $input->getEscaped('q');
$this->view->q = $q;
// do search
$index = Places_Search_Lucene::open( 4
SearchIndexer::getIndexDirectory()); 4
$results = $index->find($q); 5
$this->view->results = $results;
} else {
$this->view->messages = $input->getMessages(); 7
}
}
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.


Pages:
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
wyciągarki wróżby miłosne cukiernia-stykowscy.pl salon kosmetyczny kraków pompy ciepła