Component:

Component is base for all components specified in PXML file. Such component can represent complete view or just a one building block of it. It is used as root component of of the PXML component definition or most often as base class for such component.

Fetaures:

  • PXML root component - only Component or it's subclass can be root component of the PXML component definition
  • universal container - Component and it's subclasses can contain any class instance as direct child, provided that it is available in the scope of the document and that it has no-argument constructor
  • named components - dynamically creates properties on on instance of itself for all components that are children or grandchildren and have attribute name set - the property name is equal to the attribute value and property value is the component on which is the attribute set
  • gives view a name - title attribute of the view when specified is used as a title of the page if the component is used to instantiate the view
  • pre-execution event - Component also dispatches preExecute event that can be used to perform various task before execution of all other events in the view goes on
syntax
elementnamespacename
Componenthttp://pexeso-php.sourceforge.net/1.0Component

Example:

Cars to sell:

ModelMakePrice
CelicaToyota$ 22,000.00
IntegraHonda$ 23,000.00

Example source code

Source code of the exmaple above.

examples/ComponentExample.pxml
<?xml version="1.0" encoding="UTF-8"?>
<px:Component xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:px="http://pexeso-php.sourceforge.net/1.0"
	title="Component Example">
	
	<px:Array name="carList">
		<px:Object model="Celica" make="Toyota" price="22000"/>
		<px:Object model="Integra" make="Honda" price="23000"/>
	</px:Array>
	
	<h:p>Cars to sell:</h:p>
	<h:table>
		<h:tr>
			<h:th>Model</h:th>
			<h:th>Make</h:th>
			<h:th>Price</h:th>
		</h:tr>
		<h:tr>
			<h:td>{$self->carList[0]->model}</h:td>
			<h:td>{$self->carList[0]->make}</h:td>
			<h:td>$ {number_format($self->carList[0]->price,2)}</h:td>
		</h:tr>
		<h:tr>
			<h:td>{$self->carList[1]->model}</h:td>
			<h:td>{$self->carList[1]->make}</h:td>
			<h:td>$ {number_format($self->carList[1]->price,2)}</h:td>
		</h:tr>
	</h:table>
	
</px:Component>

This example demonstrates some of the Component's features. First is that you can specify not only components in the PXML but also a more simpler types like arrays px:Array or plain object px:Object.

Another feature is specifying of the Component's title using value assigned to the attribute title.