CodeIgniter Forums

Full Version: Removing the main-controller's name from url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have made a website which has almost all the operations under the same controller named "mainsite".
So my urls look like this: www.mydomain.com/mainsite/products or www.mydomain.com/mainsite/page/3 etc.
Is it possible to completely remove the "mainsite" -part from url with routes.php? Or with some other "trick" so that I wouldn't need to start moving everything from my mainsite-controller to other controllers?
(08-31-2015, 07:16 AM)Liquid8 Wrote: [ -> ]Hi,

I have made a website which has almost all the operations under the same controller named "mainsite".
So my urls look like this: www.mydomain.com/mainsite/products or www.mydomain.com/mainsite/page/3 etc.
Is it possible to completely remove the "mainsite" -part from url with routes.php? Or with some other "trick" so that I wouldn't need to start moving everything from my mainsite-controller to other controllers?


You can use the routes like it should be. Something like this...


PHP Code:
$route['products'] = 'mainsite/products';
$route['page/(:num)'] = 'mainsite/page/3'
Please bro, reply if that was what you were looking for.
I may be wrong, as I am certainly no expert, but is not the point of the MVC structure to not have one fat controller doing everything? I would suggest it would be best to make seperate out the functionality into relevant controllers like page, product, category etc. Alternatively you could simply rename the controller to something more appropriate, like 'Shop' or similar.
(09-01-2015, 04:39 AM)PaulD Wrote: [ -> ]I may be wrong, as I am certainly no expert, but is not the point of the MVC structure to not have one fat controller doing everything? I would suggest it would be best to make seperate out the functionality into relevant controllers like page, product, category etc. Alternatively you could simply rename the controller to something more appropriate, like 'Shop' or similar.


I agree with you my friend. But, in certain occasions, you might have few pages that you don't need to create a controller to have just one method.


I'm sure that in this case I would choose a framework for the job but, if you choose, a bunch of controllers with singles methods might only complicate the things.