Routing or remap |
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?
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 {
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?
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
|
Welcome Guest, Not a member yet? Register Sign In |