Welcome Guest, Not a member yet? Register   Sign In
invoke controll from view?
#10

[eluser]diego6616[/eluser]
Your Views should never call a method in the controller.

The basic approach is:
Models: retrieve the data, from a database, web service, file, etc.
Controllers: attend the HTTP request. Do the "application stuff" logic (basically: control all the other classes and objects).
Views: present the data in HTML.

So the filtering should be done in your model at best, controller: ok, view: never. That way, if you retrieve data, let's say, from the same table but with other filters, you could use the same view again, instead of writing one from scrap, just to make room for the filter.
Also, generally it's better to retrieve the minimum data possible from the database. That way you don't load all on PHP runtime memory just to filter it. The database can do it for you, and probably much better than PHP because it's made to handle large sets of data.
Also if you want to have a function that it's not directly connected to a controller (you probably will need again that date comparison function on other controller or view as well), it's better to locate it on a helper. Read the helper chapter on the docs, those are very easy to use and are classic procedural programming (with a few tweaks).
I know it sound like "that's a lot of code to write", but believe me, on a medium-to-large proyect, it is a bless, because generally it's easy to determine where is the code you should modify if there is a change on the app.

Anyway, if you want to do it your way, CI will let you.

Best regards.
Diego.


Messages In This Thread
invoke controll from view? - by El Forum - 03-07-2011, 05:28 AM
invoke controll from view? - by El Forum - 03-07-2011, 07:06 AM
invoke controll from view? - by El Forum - 03-07-2011, 07:07 AM
invoke controll from view? - by El Forum - 03-07-2011, 08:02 AM
invoke controll from view? - by El Forum - 03-07-2011, 08:10 AM
invoke controll from view? - by El Forum - 03-07-2011, 03:37 PM
invoke controll from view? - by El Forum - 03-07-2011, 09:22 PM
invoke controll from view? - by El Forum - 03-08-2011, 12:47 AM
invoke controll from view? - by El Forum - 03-08-2011, 12:54 AM
invoke controll from view? - by El Forum - 03-08-2011, 01:47 AM
invoke controll from view? - by El Forum - 03-10-2011, 10:58 PM
invoke controll from view? - by El Forum - 03-11-2011, 08:15 AM
invoke controll from view? - by El Forum - 03-11-2011, 09:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB