What do you call your main controller? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: What do you call your main controller? (/showthread.php?tid=63558) Pages:
1
2
|
What do you call your main controller? - DreamOfSleeping - 11-13-2015 I'm making a very simple social network, just as an exercise. I haven't got a name for it, so for this example, lets just call it poo.com. So if I'm on poo.com the url will look something like www.poo.com/index.php/controller/home Something like this would be better www.poo.com/index.php/home I know I could have a controller called "home", and just use the index function but I don't want to use a different controller for every single function. That would make writing the code a nightmare. Any suggestions? What do you call your main controller? From what I've been reading there are probably ways to get rid of the controller from the url, but even so, I still have to call the controller something. RE: What do you call your main controller? - Martin7483 - 11-13-2015 Are your pages going to be controllers or are they coming from a DB? RE: What do you call your main controller? - DreamOfSleeping - 11-13-2015 (11-13-2015, 07:39 AM)Martin7483 Wrote: Are your pages going to be controllers or are they coming from a DB? I have a database which will store blog posts. So far the controller function is called and that calls a function from the model to retrieve the posts, then the controller passes them to the view. Sorry, I'm not really sure what you mean. RE: What do you call your main controller? - Martin7483 - 11-13-2015 In normal CI a page is represented by a Controller/index method and a sub page is a method within the controller. You can also have each page be a database record. In my CMS I use this approach and have a Frontend Controller and a Backend Controller. My CMS is a collection of modules that uses HMVC. My Frontend handles the the request uri and will display the called page. RE: What do you call your main controller? - DreamOfSleeping - 11-13-2015 Thank you for replying. I'm not sure I follow you. In your first sentence you say each page is represented by controller/index method. But then you say you have a frontend controller and a backend controller. That would imply you only had two controllers and not a controller for each page. RE: What do you call your main controller? - DreamOfSleeping - 11-13-2015 Also, how can a page be a database record? Are there any examples of real projects that use codeigniter where I can see an example of what you are saying? RE: What do you call your main controller? - Martin7483 - 11-13-2015 It might be a bit vague what I mean. As I said at first, in normal CI use each page is represented by a Controller/index method and a sub page would be a method within a Controller. Lets say your default Controller set in Routes.php is named Home. http://www.socialnetwork.com would route to this Home Controller and index method http://www.socialnetwork.com/register would route to the Register Controller and index method http://www.socialnetwork.com/register/signup would route to the Register Controller and signup method You said (11-13-2015, 06:39 AM)DreamOfSleeping Wrote: I know I could have a controller called "home", and just use the index function but I don't want to use a different controller for every single function. That would make writing the code a nightmare. So to me that means you want to route all your requests to one Controller. And in that case the name should be what ever you think is a clear description of what this Controller does. Like in my case, frontend and backend. To do this you can use route rules in the Routes.php config file, or use a catch-all Controller. I use a catch-all Controller as it gives me more freedom than setting routing rules by hand. RE: What do you call your main controller? - DreamOfSleeping - 11-13-2015 Thanks again for replying. I admit already knew the first half of what you said. I think it's my fault for not making myself clear. It's a complicated topic though. If I had one page per controller. I could have a controller called "profile", which would show the users profile. I could have one called "home" which would show the users their home page. But what would I call the controller that deals with the website home, rather than the user home. Or would I just have one controller called 'home', and in the index it looks to see whether the user is logged in or not and shows the appropriate view? RE: What do you call your main controller? - Martin7483 - 11-13-2015 Ah, haha, yes it's complicated I would keep it home, and indeed depending on user status show the appropriate view RE: What do you call your main controller? - DreamOfSleeping - 11-13-2015 Aweseome thanks! And thank you for your patience! |