本文整理匯總了PHP中TemplateEngine::vars方法的典型用法代碼示例。如果您正苦於以下問題:PHP TemplateEngine::vars方法的具體用法?PHP TemplateEngine::vars怎麽用?PHP TemplateEngine::vars使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TemplateEngine
的用法示例。
在下文中一共展示了TemplateEngine::vars方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setVariable
/**
* Set a template variable
*
* @param string|array $name name of the variable
* @param string|integer|array|TemplateEngine $value value of variable
* @param boolean $local specify if value is in local scope or static
* @param boolean $force force to set a variable even it is locked
* @return void
* @access public
*/
public function setVariable($name, $value = null, $local = true, $force = false)
{
// do not allow to replace locekd variables
if (!$force && in_array($name, $this->lockedVars)) {
return;
}
//TODO remove debuggin
if (false && $name == 'tpl_content') {
$trace = debug_backtrace();
$caller = array_shift($trace);
echo 'called by ' . $caller['function'];
if (isset($caller['class'])) {
echo 'in ' . $caller['class'];
}
echo "\n<br />";
}
if (is_array($name)) {
if ($local) {
$this->localVars = array_merge($this->localVars, $name);
} else {
self::$vars = array_merge(self::$vars, $name);
}
} else {
$key = $name;
if (is_object($value)) {
// value is an object, check if it is a template object
if (__CLASS__ != get_class($value)) {
return;
}
// generate text from template
$value = $value->fetch();
}
if ($local) {
$this->localVars[$name] = $value;
} else {
self::$vars[$name] = $value;
}
}
}