Hello, it's been long days, i have posted blog, so from now, i will try to post blogs regularly as like before, and today i had this issue to make static page with single controller without multiple controller but url should be user friendly so here i'm giving you some useful tip to make your website url user friendly with single controller. how to remove controller name in the url for particular functions in the codeigniter.
LIVE DEMO
WITH CONTROLLER NAME https://demos.2my4edge.com/codeigniter/index.php/welcome/register
WITHOUT CONTROLLER NAME https://demos.2my4edge.com/codeigniter/index.php/register
the solution is here, we have to modify and add some code in Routes.php file.
In Application -> config -> routes.php file
as i showed in the top image, welcome is controller name and register is function name. here we are going to remove the controller name as showen in image. for that we need to add some code in routes.php file.
follow like the below.
$route['default_controller'] = 'welcome'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; $controllername = "welcome"; $controller_exceptions = array("register","contact"); // here regsiter & contact are controller function name. You can add as many as controller function names. foreach($controller_exceptions as $v) { $route[$v] = "$controllername/".$v; $route[$v."/(.*)"] = "$controllername/".$v.'/$1'; }
like the above code. register and contact are the function name those two functions can be addressed in url without controller name.
i hope this tutorial is more helpful for you, i will update more tutorials like this, stay connected with us.
No comments:
Post a Comment