In MVC systems (indeed many web systems) certain actions are repeated time and time again with the same output, but different display needs. A prime example would be a set of headlines, or a random comment.
One solution is to manually code this on every controller and model and then work the data into the view. While part of this can be re-used (e.g. an object wrapper for searching for data), pushing the information into the view becomes messy and introduces a lot of "cut and paste" either in the controller or in the view files.
In some systems the part of the display can be encapsulated into a single separate template which is then injected into the view via the controller. e.g. a custom function that will pre-format a table or a list of news headlines. While this may be useful for a website it does not help if you then need the output in XML or WML or some other form.
Some MVC systems adopt this method where data is fetched and formatted and then injected directly into the view.
This is bad practise as once created, the data cannot usually be transformed again (unless it is XML and an XSLT applied to it making another set of transformations on the same data). While CSS can be used to do a lot of formatting it is not an ideal situation and you still have content that is designed for only a single output type.
In Scorpio injecting data into a view should never happen. In fact the controller should not do anything more than request a specific view. It is down to the view itself to request additional information from the system. Note that these are ONLY READ requests for information, and are not modifications to the data. That is why all save, delete and set methods are blocked by the output wrapper.
This additional data is requested by using the method getControllerView() from the current view template or if using the Smarty system, the custom function: {includeView}.
This tutorial will look at setting up the controller and view to allow this to be accomplished with the guestbook data, principally to be able to display the most recent 5 entries on the home page.
Posted by: Dave Redfern (Writer), in Tutorials on 08 Jul 2008 @ 19:50
Tags: information, tutorial, views,
Contents:
Related Articles
This
work is licenced under a
Creative Commons Licence.