Skip to main content

Zen Model–View–Controller

Now we implement the data entry form for the application using the Zen Model–View–Controller (MVC) framework. The Zen MVC framework allows us to quickly and easily implement a model–view–controller design. It can dramatically simplify an application's code for displaying and updating data.

An MVC architecture separates an application's data (model) from its user interfaces (view) by inserting a layer of code (the controller) between the two. The controller code updates the model in response to user interaction with the view and updates the view in response to changes in the model. This decoupling of data from presentation provides a number of benefits including much greater code simplicity and flexibility.

To create our data entry form, we implement the following three Application Elements:

Zen MVC in the Data Entry Form
Application Element Description MVC Element

MVFILE.PersonModel

Extends %ZEN.DataModel.ObjectDataModelOpens in a new tab. Correlate the MVFILE.PersonModel properties with MVFILE.PERSON properties to include them in the model. Implement callback methods in MVFILE.PersonModel that retrieve, update, and create MVFILE.PERSON instances. Code these method using MVBASIC.

Model

Zen form component.

Connect the form component to the controller and bind each input element on the form to properties of the model class.

View

Zen dataController component.

Place this component on the page and connect it to both the form component and the model class. Controller
Note:

To learn more about Zen MVC, read Model View Controller in Using Zen Components.

For another Zen MVC example, read Part III: Updating Data using a Form and Zen MVC in the Zen QuickStart Tutorial.

FeedbackOpens in a new tab