|
From: Martin K. <Mar...@bl...> - 2003-06-05 15:47:22
|
<p>More convenience...</p>
<pre>
class XoopsObject {
...
var $tplVars = array();
...
/**
* Set variable names for Smarty template assignation (see assignTpl)
*
* Note: should be set in the constructor of the class
*
* @param mixed $vars array of variable names
*/
function setTplVars(&$vars) {
foreach ($vars as $var) {
$this->tplVars[] = $var;
}
}
/**
* Assign variables to Smarty template in a batch(see setTplVars)
*
* @param object &$tpl reference to a {@link Smarty} object
* @see Smarty
*/
function assignTpl(&$tpl) {
foreach ($this->tplVars as $var) {
$tpl->assign($var, $this->getVar($var));
}
}
/**
* Assign values to multiple variables in a batch
*
* Meant for a CGI contenxt:
* - prefixed CGI args are considered save
* - avoids polluting of namespace with CGI args
*
* Note: 'xo' stands for 'XOOPS object', it's shorter than eg 'xoops_' :-)
*
* @access private
* @param array $var_arr associative array of values to assign
* @param string $pref prefix (only keys starting with the prefix will be set)
*/
function setFormVars($var_arr=null, $pref='xo_', $not_gpc=false) {
$len = strlen($pref);
foreach ($var_arr as $key => $value) {
if ($pref == substr($key,0,$len)) {
$this->setVar(substr($key,$len), $value, $not_gpc);
}
}
}
}
</pre>
|