Codeigniter 2.0 GET params with URI rounting
Hey, I've wrote a line in my routes.php as the following:
$route['admin/trip/add'] = "admin/trip_controller/form";
But when I go to that URL in my browser, I get sent back to the main index page i.e (www.mydomain.com), does anybody know what i'm doing wrong?
I've enabled GET params in my config file too:
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
I've also tried going to a URL which doesnt use routing and I too get redirected back to th开发者_JAVA技巧e main index page.
Thanks
enable_query_strings is a configuration option that will allow you to send your controller and method via ?c=blog&m=view. This will cause trouble because obviously you aren't sending those in your query string, so CodeIgniter will assume nothing is passed and display the homepage.
You should try to use the _remap() function instead of messing with the routes.
So I guess you would have the admin.php controller.
Inside you would use the remap function which will use the second segment of the url to find what function to call.
<?php
class Admin extends Controller{
function _remap($method, $params =array())
{
if(method_exists($method))
{
$this->$method();
}
elseif($method == 'trip' && $this->uri->segment(3)=='add')
{
//do what you want here
}
}
精彩评论