Codeigniter: URL solutionless problem - codeigniter

I have following url:
http://localhost.com/phpdemo/bid/tf/red?
This url redirects through This [ $route['tf/red?'] = "abc/blue" ] to following url:
http://localhost.com/phpdemo/bid/abc/blue
Till now there is no problem. The problem starts when I attach some value with "?" like below:
http://localhost.com/phpdemo/bid/tf/red?a [It always go to default welcome page]
I have tried follwoing routes:
$route['tf/red?(:any)'] = "abc/blue"
$route['tf/red?:any'] = "abc/blue"
$route['tf/red?(a-zA-Z0-9=)'] = "abc/blue"
I have tried following config settings:
$config['permitted_uri_chars'] = 'a-z A-Z 0-9~%.:_\-';
$config['enable_query_strings'] = FALSE;
$config['allow_get_array'] = TRUE;
I also checked by using following:
$config['enable_query_strings'] = TRUE;
Now Iam clueless, what is wrong, either with Codeigniter or myself.
Can some one guide me in this regards.
Thanks in advance

I would look at the value of $config['uri_protocol'] - it is set in the main config.php file and the default is 'AUTO'.
Try each of the possible values to see which works for you - PATH_INFO or REQUEST_URI are common choices.

Related

Codeigniter: error in base_url

i have one problem with function base_url() in my codeigniter.
I'm configure the condeigniter to:
$config['base_url'] = 'sistema_clientes/';
$config['index_page'] = '';
and autoload to:
$autoload['helper'] = array('url');
It's ok, but when i'm try to use base_url('clientes') in my pages, the link repeat.
example, i wanna this : localhost/sistema_clientes/example.
<li>Example</li>
in my url, the link go to: http://localhost/sistema_clientes/sistema_clientes/clientes
but i wanna this: http://localhost/sistema_clientes/clientes
i don't wanna the base_url() repeat the sistema_clientes, please help me.
what i can do to repear this?
Thanks.
Set your base_url like below:
$config['base_url'] = 'http://localhost/sistema_clientes/';
Because setting $config['base_url'] = 'sistema_clientes/'; makes sense that
you are going to sistema_clientes controller so base_url
becomeshttp://localhost/sistema_clientes/sistema_clientes.

How to remove index segment in my codeigniter url

I am using rest controller api by phil sturgeon this is the url
paycent/user/index/id/1. Thanks in advance!
you need to set route for that.
set route in your application/config/routes.php file
$route['paycent/user/id/(:any)'] = 'paycent/user/index/id/$1';
Note : If paycent is your project name than remove it from your route. and for creating link you just need to write <?php echo site_url('paycent/user/id/1'); ?>. It will redirect to indexmethod.
In application/config/config.php :
Change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';

how to make codeigniter routing to work with paging

I have the following routes for the news that works like a charm:
$word5 = urlencode('mygreek-keyword-here');
$route[$word5] = "news/displayAllNews";
and this page display all news with the desired keyword in the address bar. But...there is always a but...I have paging on this page, so when i click on next page link...page works but with old non-friendly seo url, that is:
news/displayAllNews/10/10
while I would like to have is: mygreek-keyword-here/10/10
code that i have in my controller for the paging is as follow:
$config['base_url'] = site_url('/news/displayAllNews/'.$limit.'/');
what should i do in routes.php and in my controller to get the desired result?
Regards, John
You could get the string of URI by $this->uri->uri_string() method, and set the pagination config as follows:
$config['base_url'] = site_url($this->uri->uri_string() .'/'. $limit.'/');
Note that the URI library is loaded automatically, it doesn't need to load it manually.
Update:
Change the route rule to:
$route["$word5(.*)"] = "news/displayAllNews$1";
If it doesn't work yet, remove the .'/'. $limit.'/' phrase and let the pagination to add the limit itself by:
$config['per_page'] = 10; // or $limit, default items per page.
$config['use_page_numbers'] = FALSE;

CodeIgniter: Multilanguage when controllers hidden

Please help me. My situation is when I hide the index.php and controllers name on url like this:
localhost/ctc/index.php/controllers/function/ ==> localhost/ctc/function
It work fine and after that, I want multilanguage in my site and use tutorial from this site: http://maestric.com/doc/php/codeigniter_i18n, my url turn to:
localhost/ctc/function ==> localhost/ctc/en/function or localhost/ctc/fr/function
Problem is, when I change language from france to english, the current page turn to english (of course), but when I click to other pages, language come back to default language is france and I can't figure out why.
This is my routes.php:
$route['default_controller'] = "main/main_page";
$route['en/main/(:any)'] = "main/$1";
$route['fr/main/(:any)'] = "main/$1";
$route['en/(:any)'] = "main/$1";
$route['fr/(:any)'] = "main/$1";
$route['(:any)'] = "main/$1";
$route['^(en|fr)/(.+)$'] = "$1";
$route['^(en|fr)$'] = $route['default_controller'];
$route['404_override'] = '';

How to route everything to default controller in codeigniter?

I have a website http://example.com built using codeigniter 2. the default controller is
$route['default_controller'] = "domain";
If I try to access pageX, the link should be http://example.com/en/domain/view/pageX.
I want to allow the visitor of the website to access this page by typing
http://example.com/pageX
I have tried
$route['(:any)'] = "view/$1"; ==> it gives 404 Page Not Found
$route['(:any)'] = "domain/view/$1"; ==> it redirects to homepage with link shown as http://example.com/en/pageX
$route['(:any)'] = "en/domain/view/$1"; ==> it gives 404 Page Not Found
but non of them worked for me.
EDIT
by adding this:
$route['(:any)'] = 'domain/view/$1';
$route['en/blog'] = 'domain/view/blog';
example.com/blog will work fine
but I need it to be more general to cover all pages except admin page, something like this:
$route['(:any)'] = 'domain/view/$1';
$route['^(?!admin).*'] = 'domain/view/$o';
//The above routes will show the home page only for whatever i try!!
What is the route that i have to add to routes.php?
$route['default_controller'] is invoked if there is no URI present. Use $route['404_override'] for a full "catch all."
To get your routing pattern working, try this:
$route['[^/]*/(.*)'] = 'en/domain/view/$1';
I have managed my problem by doing this
$route['^[a-z]+$'] = 'domain/view/$1';
$route['([a-z]{2})/([a-z_]{1,50})'] = 'domain/view/$2';

Resources