Welcome Guest, Not a member yet? Register   Sign In
Search result and pagination class
#1

[eluser]djalilk[/eluser]
Hi everybody,

I need to create a search system with a keyword which displays a large result so I have to use pagination.
The problem is: how too keep the keyword variable available for all pagination pages ?
I have tried put it in an URI segment but if someone searches a word with forbdiden characters like ' an error is displayed, the 2nd solution is to put it in a session variable but it is totaly ignored by codeigniter.

Has anyone faced this problem ?

Thank you.
#2

[eluser]umefarooq[/eluser]
last days i did the search controller with pagination, you have keep you keywords with you url to keep it live, than you url is like is

Code:
http://localhost/ur_site/search/keyword/20

function search($keyword)

pagination config
$config['base_url'] = 'http://localhost/ur_site/search/'.$keyword.'/';
$config['uri_segment'] = 3;

if you calling function than you uri_segment can be 4 well check and accordingly you search will go, im also looking for good solution well its also working fine with me
#3

[eluser]djalilk[/eluser]
Thank you for answering.

This solution worked for me but what if the submited keyword contains a forbiden character like "'" ? This is not accepted and will return an error.
#4

[eluser]umefarooq[/eluser]
any example of the forbidden char please put or have you find any problem.
#5

[eluser]djalilk[/eluser]
For exemple if the keyword is "Banque D'a"
The following error is returned:


An Error Was Encountered

The URI you submitted has disallowed characters.
#6

[eluser]umefarooq[/eluser]
then we can do one thing, use php urlencode and urldecode for that, tell where error is coming while search or while pagination,
#7

[eluser]djalilk[/eluser]
This is the url I get when I use urldecode: welcome/search/banque+d'/16/1

And the same error is returned :

The URI you submitted has disallowed characters.


Below the search method I'm using
Code:
function search($keyword = null , $city= null ,$offset = null) {





if( $this->input->post('item') ) {

     $keyword = $this->input->post('item');
     $city = $this->input->post('city_id');


}

$config['base_url'] = site_url().'/welcome/search/'.urlencode($keyword).'/'.$city;
$config['total_rows'] = $this->Place->totalProductBySearch($keyword, $city);
$config['per_page'] = '1';





$this->pagination->initialize($config);
$data['result'] = $this->Place->find(urldecode($keyword), $city , $config['per_page'], $offset);
echo  $this->pagination->create_links();


$data['main'] = 'result';
$data['citys'] = $this->city->getcitysDropDown();
$this->load->vars($data);
$this->load->view('template',$data);

}
#8

[eluser]TheFuzzy0ne[/eluser]
You can use my URI-safe base_64 encoding helper. http://ellislab.com/forums/viewthread/107741/. It obfuscates the data somewhat, but it works. I also created an alternate URI syntax library which may also help. http://ellislab.com/forums/viewthread/10...10/#551378
#9

[eluser]ray73864[/eluser]
the alternative is to do it how the CI forums do it, which is to store the query if i recall, into a search database along with how many it found and generate a hash for it, then you pass the hash along in the URL.
#10

[eluser]djalilk[/eluser]
Does it mean that every query will be stored in a database ?




Theme © iAndrew 2016 - Forum software by © MyBB