Routing or remap - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Routing or remap (/showthread.php?tid=63144) |
Routing or remap - ernestlambert - 09-30-2015 I have the controller "profiles" and I want the URI "/profile/1" to map to "/profiles/view/1" also "/property/1" should map to "/properties/view/1. I want to do this for all my controllers so is there a way of writing a general rules in the routes file or via remap so that the singular of the class name followed by a slash and a number routes to the class name followed by "/view/" and the number? RE: Routing or remap - Martin7483 - 09-30-2015 You can setup routes, or you can use a MY_Controller with a _remap function and extend your controller from your MY_Controller. Create MY_Controller.php in ./application/core PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Now to use this just extend your controllers from MY_Controller instead of CI_Controller PHP Code: class Your_Controller extends MY_Controller { RE: Routing or remap - ernestlambert - 09-30-2015 Thank you for your response. The problem I experience now is that the controller "profile" does not exist, it is actually named "profiles". As such, the url "/profile/1" gives me a 404 page not found message but the url "/profiles/1" can then be handled by the _remap function...Any ideas? RE: Routing or remap - Martin7483 - 09-30-2015 Ah, I misread that in your original post. Then you should set it with routes. Add routes to the routes.php file in ./application/config PHP Code: /* Route a url with profile as the first segment to the method view in the RE: Routing or remap - ngangchill - 09-30-2015 try this library... https://github.com/Patroklo/codeigniter-static-laravel-routes |