forked from bcit-ci/CodeIgniter
-
Notifications
You must be signed in to change notification settings - Fork 0
Search with query sent via GET parameters like wordpress
World Wide Web Server edited this page Jul 4, 2012
·
14 revisions
Advantages: you can bookmark your searches, and they show up in your history, etc. (I guess this is why wordpress uses it, or maybe its just convenient, whatever).
[code] function search() {
$this->load->helper('url'); //required for base_url()
$arr = explode('?s=', $_SERVER['REQUEST_URI']);
$searchStr = isset($arr[1]) ? addslashes(urldecode(trim($arr[1]))) : '';
echo '<form method="get" action="'. base_url() . 'blog/search/">'
."Search for phrase:<br />"
."<input type='text' name='s' value='$searchStr'>"
. "<br />"
.'<input type="submit" Search>';
/*
rest of code goes here
... find data in database and display it
*/
} [/code]
- Original author: Derek Jones
- How to extend helpers: See User Guide
- Modified by: Thomas Stapleton (id, classes, selected country option and all option)
- Modified by: Bradley De-Lar (construct, setLayout example)