mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
- new method $smarty->createData([$parent]) for creating a data object (required for bugfixes below)
- bugfix config_load() method now works also on a data object - bugfix get_config_vars() method now works also on a data and template objects - bugfix clear_config() method now works also on a data and template objects
This commit is contained in:
10
README
10
README
@@ -260,14 +260,14 @@ Besides the above mentioned objects, there is also a special storage area for
|
||||
global variables.
|
||||
|
||||
A Smarty data object can be created as follows:
|
||||
$data = new Smarty_Data; // create root data object
|
||||
$data = $smarty->createData(); // create root data object
|
||||
$data->assign('foo','bar'); // assign variables as usual
|
||||
$data->conf_load('my.conf'); // load config file
|
||||
$data->config_load('my.conf'); // load config file
|
||||
|
||||
$data= new Smarty_Data($smarty); // create data object having a parent link to
|
||||
$data= $smarty->createData($smarty); // create data object having a parent link to
|
||||
the Smarty object
|
||||
|
||||
$data2= new Smarty_Data($data); // create data object having a parent link to
|
||||
$data2= $smarty->createData($data); // create data object having a parent link to
|
||||
the $data data object
|
||||
|
||||
A template object can be created by using the createTemplate method. It has the
|
||||
@@ -280,7 +280,7 @@ The first parameter can be a template name, a smarty object or a data object.
|
||||
Examples:
|
||||
$tpl = $smarty->createTemplate('mytpl.tpl'); // create template object not linked to any parent
|
||||
$tpl->assign('foo','bar'); // directly assign variables
|
||||
$tpl->conf_load('my.conf'); // load config file
|
||||
$tpl->config_load('my.conf'); // load config file
|
||||
|
||||
$tpl = $smarty->createTemplate('mytpl.tpl',$smarty); // create template having a parent link to the Smarty object
|
||||
$tpl = $smarty->createTemplate('mytpl.tpl',$data); // create template having a parent link to the $data object
|
||||
|
@@ -1,6 +1,16 @@
|
||||
01/22/2010
|
||||
- new method $smarty->createData([$parent]) for creating a data object (required for bugfixes below)
|
||||
- bugfix config_load() method now works also on a data object
|
||||
- bugfix get_config_vars() method now works also on a data and template objects
|
||||
- bugfix clear_config() method now works also on a data and template objects
|
||||
|
||||
01/19/2010
|
||||
- bugfix on plugins if same plugin was called from a nocache section first and later from a cached section
|
||||
|
||||
|
||||
###beta 7###
|
||||
|
||||
|
||||
01/17/2010
|
||||
- bugfix on $smarty.const... in double quoted strings
|
||||
|
||||
|
@@ -203,7 +203,9 @@ class Smarty extends Smarty_Internal_Data {
|
||||
// autoload filter
|
||||
public $autoload_filters = array();
|
||||
// status of filter on variable output
|
||||
public $variable_filter = true;
|
||||
public $variable_filter = true;
|
||||
// default modifier
|
||||
public $default_modifiers = array();
|
||||
// global internal smarty vars
|
||||
public $_smarty_vars = array();
|
||||
// start time for execution time calculation
|
||||
@@ -346,6 +348,63 @@ class Smarty extends Smarty_Internal_Data {
|
||||
return $template->isCached();
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a data object
|
||||
*
|
||||
* @param object $parent next higher level of Smarty variables
|
||||
* @returns object data object
|
||||
*/
|
||||
public function createData($parent = null)
|
||||
{
|
||||
return new Smarty_Data($parent, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a template object
|
||||
*
|
||||
* @param string $template the resource handle of the template file
|
||||
* @param object $parent next higher level of Smarty variables
|
||||
* @param mixed $cache_id cache id to be used with this template
|
||||
* @param mixed $compile_id compile id to be used with this template
|
||||
* @returns object template object
|
||||
*/
|
||||
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null)
|
||||
{
|
||||
if (is_object($cache_id) || is_array($cache_id)) {
|
||||
$parent = $cache_id;
|
||||
$cache_id = null;
|
||||
}
|
||||
if (is_array($parent)) {
|
||||
$data = $parent;
|
||||
$parent = null;
|
||||
} else {
|
||||
$data = null;
|
||||
}
|
||||
if (!is_object($template)) {
|
||||
// we got a template resource
|
||||
// already in template cache?
|
||||
$_templateId = crc32($template . $cache_id . $compile_id);
|
||||
if (isset($this->template_objects[$_templateId]) && $this->caching) {
|
||||
// return cached template object
|
||||
$tpl = $this->template_objects[$_templateId];
|
||||
} else {
|
||||
// create new template object
|
||||
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
|
||||
}
|
||||
} else {
|
||||
// just return a copy of template class
|
||||
$tpl = $template;
|
||||
}
|
||||
// fill data if present
|
||||
if (is_array($data)) {
|
||||
// set up variable values
|
||||
foreach ($data as $_key => $_val) {
|
||||
$tpl->tpl_vars[$_key] = new Smarty_variable($_val);
|
||||
}
|
||||
}
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads security class and enables security
|
||||
*/
|
||||
|
@@ -158,7 +158,6 @@ class Smarty_Internal_Data {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* clear the given assigned template variable.
|
||||
*
|
||||
@@ -278,49 +277,38 @@ class Smarty_Internal_Data {
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a template object
|
||||
* Returns a single or all config variables
|
||||
*
|
||||
* @param string $template the resource handle of the template file
|
||||
* @param object $parent next higher level of Smarty variables
|
||||
* @param mixed $cache_id cache id to be used with this template
|
||||
* @param mixed $compile_id compile id to be used with this template
|
||||
* @returns object template object
|
||||
* @param string $varname variable name or null
|
||||
* @return string variable value or or array of variables
|
||||
*/
|
||||
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null)
|
||||
function get_config_vars($varname = null)
|
||||
{
|
||||
if (is_object($cache_id) || is_array($cache_id)) {
|
||||
$parent = $cache_id;
|
||||
$cache_id = null;
|
||||
}
|
||||
if (is_array($parent)) {
|
||||
$data = $parent;
|
||||
$parent = null;
|
||||
} else {
|
||||
$data = null;
|
||||
}
|
||||
if (!is_object($template)) {
|
||||
// we got a template resource
|
||||
// already in template cache?
|
||||
$_templateId = crc32($template . $cache_id . $compile_id);
|
||||
if (isset($this->smarty->template_objects[$_templateId]) && $this->smarty->caching) {
|
||||
// return cached template object
|
||||
$tpl = $this->smarty->template_objects[$_templateId];
|
||||
if (isset($varname)) {
|
||||
if (isset($this->config_vars[$varname])) {
|
||||
return $this->config_vars[$varname];
|
||||
} else {
|
||||
// create new template object
|
||||
$tpl = new $this->template_class($template, $this->smarty, $parent, $cache_id, $compile_id);
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
// just return a copy of template class
|
||||
$tpl = $template;
|
||||
return $this->config_vars;
|
||||
}
|
||||
// fill data if present
|
||||
if (is_array($data)) {
|
||||
// set up variable values
|
||||
foreach ($data as $_key => $_val) {
|
||||
$tpl->tpl_vars[$_key] = new Smarty_variable($_val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deassigns a single or all config variables
|
||||
*
|
||||
* @param string $varname variable name or null
|
||||
*/
|
||||
function clear_config($varname = null)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
unset($this->config_vars[$varname]);
|
||||
return;
|
||||
} else {
|
||||
$this->config_vars = array();
|
||||
return;
|
||||
}
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,12 +337,15 @@ class Smarty_Data extends Smarty_Internal_Data {
|
||||
// back pointer to parent object
|
||||
public $parent = null;
|
||||
// config vars
|
||||
public $config_vars = array();
|
||||
public $config_vars = array();
|
||||
// Smarty object
|
||||
public $smarty = null;
|
||||
/**
|
||||
* create Smarty data object
|
||||
*/
|
||||
public function __construct ($_parent = null)
|
||||
public function __construct ($_parent = null, $smarty = null)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
if (is_object($_parent)) {
|
||||
// when object set up back pointer
|
||||
$this->parent = $_parent;
|
||||
@@ -363,7 +354,7 @@ class Smarty_Data extends Smarty_Internal_Data {
|
||||
foreach ($_parent as $_key => $_val) {
|
||||
$this->tpl_vars[$_key] = new Smarty_variable($_val);
|
||||
}
|
||||
} else {
|
||||
} elseif ($_parent != null) {
|
||||
throw new Exception("Wrong type for template variables");
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty method Get_Config_Vars
|
||||
*
|
||||
* Returns a single or all global config variables
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage SmartyMethod
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Deassigns a single or all global config variables
|
||||
*
|
||||
* @param object $smarty
|
||||
* @param string $varname variable name or null
|
||||
*/
|
||||
function Smarty_Method_Clear_Config($smarty, $varname = null)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
unset($smarty->config_vars[$varname]);
|
||||
return;
|
||||
} else {
|
||||
$smarty->config_vars = array();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty method Get_Config_Vars
|
||||
*
|
||||
* Returns a single or all global config variables
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage SmartyMethod
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a single or all global config variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a single or all global config variables
|
||||
*
|
||||
* @param string $varname variable name or null
|
||||
* @return string variable value or or array of variables
|
||||
*/
|
||||
function Smarty_Method_Get_Config_Vars($smarty, $varname = null)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
if (isset($smarty->config_vars[$varname])) {
|
||||
return $smarty->config_vars[$varname];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return $smarty->config_vars;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user