I have created a codeigniter 3 project but I have set the name of controller as "exampleController" which is showing on my URL. I want to remove the word "controller" to setup custom routes. How can I do it?
$route['alt-text'] = 'AltTextController/index'; // Route for the index method (loading the view)
$route['alt-text/upload'] = 'AltTextController/uploadPdf'; // Route for uploading a PDF
$route['alt-text/delete'] = 'AltTextController/deletePdf'; // Route for deleting a PDF
$route['User/alt-text'] = 'UserController/AltText';// $route['']
I have set these in routes. Please help me to understand
2
Answers
In CodeIgniter, you can’t directly remove the word "controller" from the class name itself, but you can certainly set up custom routes to avoid "controller" appearing in the URL.
Configuring routes allows you to map URLs to specific controller methods, effectively hiding the actual controller class name from the URL the way you specified.
CodeIgniter in its version 3 uses by default the name of the controller and the method, to modify this and add friendly urls you can do it in the following way, go to application/config/routes.php and modify the route as follows
you can place the verb associated with the route in this example it is of the GET type