简体   繁体   中英

codeigniter routing uri with default_controller

Hi everyone im new with codeigniter. my routes.php is

$route['default_controller'] = "Maincontroller";
$route['(:any)'] = "Maincontroller/user_index/$1";

i want to search people if they type in the URL = www.site.com/username but my problem is when going to other controller. should i route all my controllers?

$route['default_controller'] = "Maincontroller";
$route['somecontrollers'] = 'somecontrollers';
$route['(:any)'] = "Maincontroller/user_index/$1";

then how about my methods.

i tried this remap

public function _remap($method, $params = array())
{ 
    if (method_exists(__CLASS__, $method)) {
        $this->$method($params);
    } else {
        $this->user_index($method);
    }
}

but this only works properly in controller which is not default, and i get the result i want. but as i apply this in my default controller it doesnt work well.

Hope this one help you!

$route['Maincontroller/(:any)'] = 'Maincontroller/user_index/$1';
$route['somecontrollers/(:any)'] = 'somecontrollers/user_index/$1'; 

$route['(:any)'] = "user_index/$1"; 

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