[eluser]Unknown[/eluser]
Hello I have been using CodeIgniter for over a year now and have recently starting using a second php mvc framework for a different (already in progress) project. One very useful feature that I found in this second framework is the idea of "modular views". I am wondering if I have been missing something in CodeIgniter and if this can actually indeed be accomplished with CI. Let me explain first...
So in CI I have a view called mycontacts.php. This view is a little box that goes in a sidebar and displays my 5 newest contacts. So in my Welcome::index() function for example, I do the php processing to get my 5 newest contacts and store it in a $data array. This variable, along with some other variables are passed into my index.php view and then the $data array of my 5 newest contacts is passed when loading the mycontacts.php view. My 5 newest contacts are properly displayed. Now lets say on my profile page...i want to display this as well. I can resuse the view obviously, but now in the Profile::index() function, I need to do that same php processing to get get my 5 newest contacts again...and pass it along to the mycontacts.php when loading it from the profile index view. If I want to load this mycontacts.php view 50 times....you see where this is going.
In framework #2 loading a view is directly correlated to one controller::function(). so instead of having to do php processing
every time i want to display my 5 newest contacts, i just have a function in lets say my user controller called "mycontacts()". anytime i load the mycontacts.php view, the php processing occurs within that User::mycontacs() function and is then available within the mycontacts.php view. Note that the User controller is specified when loading the mycontacts.php view in framework #2, so mycontacts() function is
only in User controller. You can see how much more modular this is, cleaner it is, reusable, and how much less repetitive code you need to write.
Am I missing something in CI? Can this be done? This seams like a must have.
Thanks!
Kevin