template

Every controller has a template object as one of its public variables. Basically the allows you to show views (html files with data) to your user. It’s a best practice to not do any logic or database work inside your views. Views are stored in the paths.views configuration setting folder. Views should be named int he format of file.view.php.

Parent Class

None


Public Properties

$vars
This is an associative (key->value pairs) array containing all the data you have provided to this template. Essentially, your controller builds a “model” by storing values in this associative array. The view then has access to that model via referencing the values in this array. In this way, you can create a list of $vars from a variety of sources and so long as the data exists in this array, your view won’t care how it got there. This helps separate the business logic (controller logic) from the data itself (the model) and the view.
Data Type: array
Default Value: Associative array with precisely 3 key value pairs… ‘skin’, ‘header’, and ‘json’. skin is a string that is the name of the jQueryUI skin. header is an array of values to put in the HTTP headers and json is an array of values to send as json when applicable.
$showViewFilename
If set to true, the template will create a HTML comment block with the name of the view file prior to loading the view itself. This is handy for debugging.
Data Type: boolean
Default Value: false

Public Methods

\ipinga\template __construct( [ \ipinga\htmlGenerator $htmlGenerator ] )
The constructor does all the normal instantiation stuff, but it also creates a view template variables (in the $vars associative array). $vars[‘html’] will be a reference to an instance of defaultHtmlGenerator unless you provide your own. $vars[‘skin’] is set by default to ‘cupertino’. $vars[‘header’] and $[‘json’] are set to empty arrays by default as well.
Parameters:
$htmlGenerator (\ipinga\htmlGenerator: optional) an instance of the html generator you want this template/view to use. It should be an object that extends the base htmlGenerator class. Default: an instance of the \ipinga\defaultHtmlGenerator class
Returns:
An instance of \ipinga\template
void __set( $index, $value )
This is the setter to help in creating the $vars model
Parameters:
$index (string) is the name of variable you wish to pass to the template
$value (mixed) is the value of the variable is can be of any data type
Returns:
null
Example:
mixed __get( $index )
This is the getter to help in accessing the $vars model
Parameters:
$index (string) is the name of variable you wish to locate from within your view
Returns:
The value associated with the $index
Example:
void show( string $filename[, array $newVars ] )
This function passes control to your view file
Parameters:
$filename (string) is the base filename for your view file. If you pass ‘xyz’, then this function will expect to find a file called ‘xyz.view.php’ in the folder specified in the paths.views configuration setting
$newVars (array: optional) allows you to completely replace anything that might currently be in the $vars array. Default: null
Returns:
null
Example:
void include_file( string $filename )
Including a file isn’t as simple as the normal PHP include or require functions, since we want to expose the $vars model to the file we are including. This little function takes care of that for you. If you don’t need access to that model, then it would be faster to use the normal PHP include or require functions.
Parameters:
$filename (string) is the base filename for your include file. If you pass ‘xyz’, then this function will expect to find a file called ‘xyz.php’ in the folder specified in the paths.views configuration setting
Returns:
null
Example:

Example Controller/Method and View