1
votes

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.

1
CI routing has ordering.If you have other controller you should not use any routes.If You still need any you should write rules for others controllers.In that case a username cannot be like a controller name - Shaiful Islam

1 Answers

0
votes

Hope this one help you!

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

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