electronic.alchemy :: View
where the past meets the future
pike > Fins > Developer > View


Created by hww3. Last updated by hww3, 17 years ago. Version #1.

In the MVC design paradigm, a view is a particular user interface segment that is presented to the user as a result of a controller event being triggered. Usually, the view is provided with some data, courtesy of the model. In Fins, each application has an instance of the View system, usually in the form of an instance of a class derived from Fins.FinsView. This class is the entry point into the user interface portion of the Fins framework. In the case of Fins, a given user interface segment is defined by a template, with data provided to the template during rendering. A template is represented in the application by an instance of Fins.Template.Template; the most commonly used template style is called SimpleTemplate, which uses a JSP-esque markup idiom that we call "PSP", for Pike Server Pages. In order to simplify use, FinsModel provides a way to request a Fins.Template.View object, which is basically a container for a Template object and a TemplateData object. The Fins.Template.View class provides some convenience functions for adding data and performing the final rendering of the View.

FinsView contains a field for specifying the default template type used by the application. This is used by the get_view convenience function to get the desired template for rendering. The usage for this method is: get_view(view_name), where view_name is the name of a template file, minus its extension, relative to the applications' template/ directory. The default extension for SimpleTemplate is ".phtml", and the default extenstion for XSLTTemplate is "xml". The application's FinsView object is available to controllers as "view".

As an example, the following code loads the template index.phtml, adds some data to the dataset and sets it as the application's response to the controller event foo:

void foo(Fins.Request request, Fins.Response response, string ... data)
  Fins.Template.View v = view->get_view("index");   
  v->add("datapoint", "somevalue");

In certain cases, it may be desireable to bypass the use of Fins.Template.View, and work directly with Template and TemplateData objects. Refer to the module reference for details of methods in FinsView and Response that pertain to getting and setting templates and data.

Obviously, you can create your own templating system as long as it implements the Fins.Template.Template interface. As an example, FinScribe extends SimpleTemplate to provide dynamically themed views.

Not categorized | RSS Feed | BackLinks

comments powered by Disqus