Yajli Maclo Yajli Maclo - 2 months ago 10
PHP Question

How to route cutom URL with to custom controller in CodeIgniter?

I have a PHP CodeIgniter Controller with name

User
and have a method that get details of user
user_detail($username)


Now when i need to show user data for example for userName
mike


I call this URL

http://www.example.com/user/user_detail/mike

My target

How to make user data accessible by next URLs

http://www.example.com/user/mike

or / and

http://www.example.com/mike

Answer

You have to read the this page from the official documentation of codeigniter. It covers all related things to Routing URLs easily. All routes must be configured via the file:

application/config/routes.php

It could be something like this :

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