Home > PHP > PHP - Class to handle page layout

PHP - Class to handle page layout

Template.class.php

Within this file we find the class template, the parties of interest are outlined below for completeness:

class Template {

= const DELIMIT_SX'[__';
= const DELIMIT_DX'__]';

... ... ... ... ... ... ... ... ... ...

public function __construct ($ docroot ='./') {...}

public function setDocRoot ($ docroot) {...}

getDocRoot public function () {...}

public function addfiles ($ files) {...}

public function getFile ($ key = 'all') {...}

public function setVariable ($ name, $ value, $ append = false) {...}

public function setVariableByVariable ($ name, $ nameBy, $ append = false) {...}

public function GetVariable ($ name = 'all') {...}

public function getOutput ($ key, $ outputToVideo = false) {...}

}

The first two lines of the class are the constants that are used to delimit tags within the templates. If you want to use other delimiters in your html file and just modify DELIMIT_SX DELIMIT_DX.

public function __construct ($ docroot ='./')
__construct () is the class constructor, which initializes the default state of the object. $ docroot parameter contains the path where the template files are present.

public function setDocRoot ($ docroot)
setDocRoot () sets the $ docroot with the actual path where you have the html template.

getDocRoot public function ()
getDocRoot () retrieves the value in the property $ docroot.

public function addfiles ($ files)
addfiles () allows you to record in the property file contents $ template files we're going to use, passed through the paremtro the input method. If the input parameter is an array, or one of its elements does not represent a template in the file system will be thrown.

public function getFile ($ key = 'all')
method retrieves one or more items of property $ class files. If you are using it without passing any parameters will retrieve an array containing the names of the template, otherwise it will return the contents of the file whose name is contained in $ key.

public function setVariable ($ name, $ value, $ append = false)
setVariable () allows the value to a property $ values, $ name parameter contains the name of the variable present in a html template, while value is the value to replace the variable. $ Append indicates if the new value for the variable will replace the one already present or will be appended to it.

public function setVariableByVariable ($ name, $ nameBy, $ append = false)
setVariableByVariable () allows the value to a property $ values, $ name parameter contains the name of the variable present in a html template, while $ nameBy is the name of a variable in an html template whose value, if present in $ values , will be inserted into the element key values ​​of $ $ name. $ Append indicates if the new value for the variable will replace the one already present or will be appended to it.

public function GetVariable ($ name = 'all')
GetVariable () retrieves the property value in $ values. If $ name is the same as 'all' will be refunded the entire property $ class values, or the value contained in the name of whose position is detected.

public function parseTemplate ($ variable, $ template, $ append = false)
parseTemplate () takes the contents of a template, identified by the $ template, and inserts it into a template variable, identified by the parameter $ variable, $ append if true worth in the $ content variable is added to the value already present in Otherwise, the contents of $ template overwrites the old contents of $ variable. Below you replace all the variables with the same content as can be seen in the foreach loop, and finally executes the required setting.

public function getOutput ($ key, $ outputToVideo = false)
getOutput () allows you to retrieve the resulting HTML directly returning or displaying it on screen, in relation to the value of the parameter $ outputToVideo. First of all the html property is set by the content of the class whose key is defined by the parameter $ key, then replace the variables present in the html with the appropriate values ​​and finally performs the requested action on the variables that are not yet exploited . Finally you decide whether to return the html of interest or viasulizzarlo screen directly.

Tag: , , Categories: PHP Tags: , ,
  1. No comments yet ...
  1. No trackbacks yet ...
Immagine CAPTCHA
Audio CAPTCHA
Change image
*