CodeIgniter Forums
Removing the main-controller's name from url - 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: Removing the main-controller's name from url (/showthread.php?tid=62828)



Removing the main-controller's name from url - Liquid8 - 08-31-2015

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?


RE: Removing the main-controller's name from url - JoelPiccoli - 08-31-2015

(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'



RE: Removing the main-controller's name from url - JoelPiccoli - 08-31-2015

Please bro, reply if that was what you were looking for.


RE: Removing the main-controller's name from url - PaulD - 09-01-2015

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.


RE: Removing the main-controller's name from url - JoelPiccoli - 09-01-2015

(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.