Views

A view is simply a web page, or a page fragment, like a header, footer, sidebar, etc. In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy.

Views are never called directly, they must be loaded by a controller. Remember that in an MVC framework, the Controller acts as the traffic cop, so it is responsible for fetching a particular view. If you have not read the Controllers page you should do so before continuing.

Using the example controller you created in the controller page, let's add a view to it.

Using your text editor, create a file called blogview.lc, and put this in it:

To load a particular view file you will use the following function:

There is a second optional parameter which lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser.

revIgniter will intelligently handle multiple calls to rigLoadView() from within a controller. If more than one call happens they will be appended together.

Your view files can also be stored within sub-folders if you prefer that type of organization. When doing so you will need to include the folder name loading the view.

Data in the global array variable gData is merged with the view. Here is an example using the gData array:

The data array in gData is not limited to simple variables. You can use multiple items or multi dimensional arrays, which can be looped to generate multiple rows.