简体   繁体   中英

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 ie (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 the 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
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM