Welcome Guest, Not a member yet? Register   Sign In
Add admin paths to your routes config
#1

[eluser]oddman[/eluser]
After having played around with a few different MVC frameworks, there are a few things that I'm bringing back to codeigniter (reason why I'm here is because CI is arguably the fastest MVC framework currently available in the languages I work with). So, here I present to you a solution for admin paths (which get built into your usual controllers). Let's say for example you have a products URL: /products/some-product-name/. There's a lot of functionality in there that we may not necessarily want to re-write, especially within that controller. So what we want to do is alter the routes so that we can use that controller for admin as well:

Code:
$route['admin/?'] = 'home/admin_index';
$route['admin/([a-z]+)/?'] = '$1/admin_index';
$route['admin/([a-z]+)/([a-z]+)'] = '$1/admin_$2';

What we're doing, is taking all requests that start with 'admin' and converting them to use specific actions (convention over configuration). So as an example, if I were to go to:

/admin/products/

This would, in fact - point the request to the Products controller, and call the admin_index method.

Why do we want to do this? We're sharing code for the products controller with the admin, and simply placing administration restrictions on code we've already written. By calling admin views, we then also customize the way it is displayed.

Hope this helps others Smile




Theme © iAndrew 2016 - Forum software by © MyBB