CodeIgniter Forums
Should it be a controller or method? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Should it be a controller or method? (/showthread.php?tid=12451)



Should it be a controller or method? - El Forum - 10-19-2008

[eluser]jleequeen[/eluser]
Hi all,

I have a question concerning how you make the decision to make something a controller instead of a method. I know that basically it probably is subjective and up to individual taste, but it's still nice to hear some views on the subject. Let me give you something I'm facing at the moment.

I have an application that up until now has not had a "dashboard" so to speak, it just defaulted to one of the crud controllers. Well, I need a dashboard now to put multiple things on and was wondering where something like that could go.

With crud based controllers it's easy. You typically have one per database (or model) and then expand from there. I've always had some issues of when to create new controllers, especially in this situation were we are only talking about a dashboard page. Is it worth creating a controller all it's own for it? And what about if I have two different types dashboards for different users?

I could also just put the dashboard "screen" up under say my admin controller. so to access it would be "admin/dashboard". But, is dashboard really an action?

Decisions, decisions?? What do you think?


Should it be a controller or method? - El Forum - 10-19-2008

[eluser]GotPHP.com[/eluser]
Given the scenario you described, I would setup a dashboard controller. This would allow you to do dashboard/admin, dashboard/user, dashboard/reports, etc. Once you have a dedicated dashboard controller, it can expand as your app expands.

Just my opinion.


Should it be a controller or method? - El Forum - 10-19-2008

[eluser]Colin Williams[/eluser]
Dashboard is an action (the action is "access the dashboard"). I think you would have one "dashboard" method that is pluggable in such a way that outside actors can hook into this method and add widgets (if it makes sense to have it opened up in that manner).


Should it be a controller or method? - El Forum - 10-20-2008

[eluser]meglio[/eluser]
I like the decision of Summer Student.
The only thing is that you must decide if you are going to have multiple pages related to dasboard, eg editing, viewing, reporting etc, and if this is the case then you definitely need dasboard controller.


Should it be a controller or method? - El Forum - 10-20-2008

[eluser]Bramme[/eluser]
I had a similar situation and just ended up with creating a "general" controller, this had a dashboard function (which index referred to) but also some profile editting and a settings page. then I made controllers for each database table (news/blog - tutorials...)


Should it be a controller or method? - El Forum - 10-20-2008

[eluser]Colin Williams[/eluser]
I think each controller should have its own dashboard (if it needs one), but there could be one Dashboard Controller that is a portal for all of them. Actually, in the one app I have done with a dashboard, it was part of the User controller (a "dashboard" method of the User controller).


Should it be a controller or method? - El Forum - 10-20-2008

[eluser]jleequeen[/eluser]
Thanks to everyone that has given me their two cents. I think I'm going to do a hybrid approach. I've gone ahead and created the dashboard under the "user" controller as an action. But if I see the need to do anything more with the dashboard than just showing a simple page (that currently has no interactions of it's own other than displaying data and links to other controllers) then I will move it to it's own controller and expand from there.