Consider the following example of a Marmot application making use of the Presentation Layer:
The output from this example and the others in this chapter can be seen in the "examples" directory included in the Marmot distribution. It can be accessed at http://your-server/phpapps/mu/examples/.
We must first instantiate a new MU_Presentation object:
We can then call the MU_Presentation::add_body() method to add a body to our document:
Think of the body as a container that holds the rest of the document. $body is a reference to an MU_XML_Element object. Using this reference, we can place additional elements within the body, like a form or a heading. (We will discuss these elements in detail later in the chapter. Though the code used to create the form is relatively simple, quite a lot is being done. Marmot lays out the elements of the form, validates the input returned by the user- the name field cannot be blank- redisplaying the form with errors highlighted if there are any, and presents everything within the framework of a theme.)
Finally, we invoke the MU_Presentation::display() method to give our page a title, our application a name, and process and display the themed output:
As you can see, the Presentation Layer greatly reduces the effort required to create a web application. In addition, the programmer does not have to interact with HTML at all.