CodeIgniter Forums
Number of controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Number of controllers (/showthread.php?tid=22587)



Number of controllers - El Forum - 09-14-2009

[eluser]Mario Rojas[/eluser]
Hi everybody!! I'm newbie on CI forum and I have a confused question about development...

I need to build a crimes search engine with session, when the admin can add, delete, insert and modify data, and the common user only search info. First I thought in two controllers (users for login system and a main controller for admin activities and search data)

Should I develop my webapp with two controllers? or I need to code one controller for all the webapp like the examples of the user guide?

How many controllers needs a webapp?


Number of controllers - El Forum - 09-14-2009

[eluser]Aken[/eluser]
As many as you want...


Number of controllers - El Forum - 09-14-2009

[eluser]jedd[/eluser]
Hi Mario,

I'd suggest you should have one controller that provides add, delete, insert (same as add?), modify and search - and control access to each of those methods using whatever authentication / access library you're using/writing.

This will reduce the amount of code you need to duplicate.


Number of controllers - El Forum - 09-14-2009

[eluser]Mario Rojas[/eluser]
[quote author="jedd" date="1252994300"]Hi Mario,

I'd suggest you should have one controller that provides add, delete, insert (same as add?), modify and search - and control access to each of those methods using whatever authentication / access library you're using/writing.

This will reduce the amount of code you need to duplicate.[/quote]

AHAHAHA thanks!!! I thought too in a main controller with an auth module (like kohana) or library... there are several libraries about it... but, the general idea is one controller per app? this method works in other kind of projects? when can I use more than one controller?


Number of controllers - El Forum - 09-15-2009

[eluser]jedd[/eluser]
[quote author="Mario Rojas" date="1253009281"]
.. but, the general idea is one controller per app? this method works in other kind of projects? when can I use more than one controller?
[/quote]

Ah, no. The general idea is one controller per resource.

Resource is a curious word for both native speakers and nesbis, so one controller per noun - or 'thing that you do stuff with'. The 'doing stuff' bits (verbs), of course, are your methods -- in this instance the adds, deletes and searches. (Generally speaking, of course. You'll have exceptions, but it's a good way to start thinking about the problem.)

You should check out some MVC and CI tutorials to get a better angle on how other people split their projects up.

In any case, as a general rule you shouldn't be splitting up controllers based on who might hit them. As I mentioned before, this is up to your authentication system to manage - but if both admins and non-admins are allowed to run the same search function against a part of your database, it makes sense for that search function to exist in just one controller ... right?

Oh, and in the interests of fair and balanced reporting, some people like to have an admin 'back office' controller to do all the, well, adminy works. But these tend to be functions that only an admin can do, and are functions for managing the site.


Number of controllers - El Forum - 09-15-2009

[eluser]Mario Rojas[/eluser]
Oh well, for newbies like me, is a little difficult think about it... but, i need to reed more examples...

do somebody knows any CMS based on CodeIgniter?


Number of controllers - El Forum - 09-15-2009

[eluser]jedd[/eluser]
[quote author="Mario Rojas" date="1253063795"]Oh well, for newbies like me, is a little difficult think about it... but, i need to reed more examples...

do somebody knows any CMS based on CodeIgniter?[/quote]

The wiki contains a few references to full sites running CI, where the code is available.

There's [url="http://ellislab.com/forums/viewthread/129017/"]this recent thread[/url] which is definitely worth a look (though don't expect a lot of in-line documentation Wink.

The big one, though, if it's a CMS you want, is [url="http://github.com/philsturgeon/pyrocms"]pyroCMS[/url]. The only problem there, I reckon, for a newbie, is the fact it uses HMVC - or modularised controller/view/model groupings.