Creating Views

From XOMBO Documentation

Jump to: navigation, search

Contents

Introduction

Creating a View is a little more tricky because of the security steps involved. Views handle the presentation and organization of all the data in the system. It's what outputs data in a way that the user's browser can understand. While a DBObject handles the loading and saving of data records, the View helps choose how to present it and what other objects to combine it with. When using the Developer Utilities, you can have it automatically generate a template view based on the control you make which you can later customize.

Creating the ViewObject

This tutorial assumes you are using the examples from the DBObject tutorial.

File ./scripts/templates/view.template      ★      SVN http://svn.xombo.org/svn/platform/current/trunk/scripts/templates/view.template API DOCS

Open the view template file. Rename the class to something more reasonable. Usually, you will want to name the view the plural form of whatever DBObjects it will be responsible for managing. In our case, we'll call this view “Breeds” and name the file /view/breeds.view.php.

Change instances of “TemplateObj” to the name of the DBObject you are using. In our case, “Breed”. This template gives us enough boilerplate code to display a tabular list of all our objects, pull up an editor form, save the information from the editor, and delete entries. You can repeat these steps for a “Pets” view.

Once your “Pets” view is created and both tables are populated with data, you will notice that when you edit a Pet instance, it allows you to select the Breed from a drop-down list. The system knows enough about the setup of your tables to populate and prepare this form automatically.

Some protected template values are available within the context of the View object automatically that give convenient access to the User_ID, Vendor_ID, Authenticated status, etc...

Adding the View to the System

Now that you have created the view, you must add it to the system and grant permissions to the proper user types. Consult the vendor & system administration manuals for more information.

Advanced ViewObject Tactics

You can add additional actions to your view. Simply create new public functions that echo output to stdout. You can call these functions with $DBObject->editor() callbacks and Link library calls. Check out the template's edit(), save(), and delete() functions for insight into how to achieve your goal.

Second, you can customize the built-in functions to achieve a particular interface style or to limit the data fields the user is allowed to modify. Consult with the appropriate Library section for more information.

Personal tools