neilakapete
neilakapete

Reputation: 1178

Searching with Codeigniter using the url to include disallowed URI characters

I want to implement a search in codeigniter using the search term in the url string but am having trouble allowing disallowed uri characters (' is the main problem)

e.g. www.example.com/search/find/search_term/collector's edition/category/stackoverflow

basically find 'collector's edition' in category 'stackoverflow'

This throws the URI exception error - even if I encode it with javascript codeigniter unencodes it. Obviously I don't want to go and allow all characters.

I also want to be able to decode my data when it is returned so I can display the search term in the input box also.

Upvotes: 2

Views: 985

Answers (2)

No Results Found
No Results Found

Reputation: 102824

Use a query string rather than fight against CI's suggested allowed URI characters:

example.com/search/?search_term=collector's+edition&category=stackoverflow

Just make sure you have query strings ($_GET) enabled:

$config['allow_get_array'] = TRUE; // This enables $_GET data

// The name of this item is misleading, it's not what you might think 
$config['enable_query_strings'] = FALSE; // <-- Ignore this, make sure it's FALSE

And to grab the search term:

$query = $this->input->get('search_term'); // No need to decode

Upvotes: 1

Ali Gajani
Ali Gajani

Reputation: 15091

You need to add “=” to your allowed_uri_chars. You’ll find that string in your config/config.php file.

It could also be the . (dot) in there. Try adding a dot instead. You need to be a little bit brave and experiment to figure out what works.

Try $config[‘permitted_uri_chars’] = ‘a-z 0-9~%.:?=_\-’;

Upvotes: 0

Related Questions