mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 11:54:26 +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.
|
global variables.
|
||||||
|
|
||||||
A Smarty data object can be created as follows:
|
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->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
|
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
|
the $data data object
|
||||||
|
|
||||||
A template object can be created by using the createTemplate method. It has the
|
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:
|
Examples:
|
||||||
$tpl = $smarty->createTemplate('mytpl.tpl'); // create template object not linked to any parent
|
$tpl = $smarty->createTemplate('mytpl.tpl'); // create template object not linked to any parent
|
||||||
$tpl->assign('foo','bar'); // directly assign variables
|
$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',$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
|
$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
|
01/19/2010
|
||||||
- bugfix on plugins if same plugin was called from a nocache section first and later from a cached section
|
- bugfix on plugins if same plugin was called from a nocache section first and later from a cached section
|
||||||
|
|
||||||
|
|
||||||
|
###beta 7###
|
||||||
|
|
||||||
|
|
||||||
01/17/2010
|
01/17/2010
|
||||||
- bugfix on $smarty.const... in double quoted strings
|
- bugfix on $smarty.const... in double quoted strings
|
||||||
|
|
||||||
|
@@ -204,6 +204,8 @@ class Smarty extends Smarty_Internal_Data {
|
|||||||
public $autoload_filters = array();
|
public $autoload_filters = array();
|
||||||
// status of filter on variable output
|
// status of filter on variable output
|
||||||
public $variable_filter = true;
|
public $variable_filter = true;
|
||||||
|
// default modifier
|
||||||
|
public $default_modifiers = array();
|
||||||
// global internal smarty vars
|
// global internal smarty vars
|
||||||
public $_smarty_vars = array();
|
public $_smarty_vars = array();
|
||||||
// start time for execution time calculation
|
// start time for execution time calculation
|
||||||
@@ -346,6 +348,63 @@ class Smarty extends Smarty_Internal_Data {
|
|||||||
return $template->isCached();
|
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
|
* Loads security class and enables security
|
||||||
*/
|
*/
|
||||||
|
@@ -158,7 +158,6 @@ class Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clear the given assigned template variable.
|
* 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 string $varname variable name or null
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @return string variable value or or array of 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)
|
function get_config_vars($varname = null)
|
||||||
{
|
{
|
||||||
if (is_object($cache_id) || is_array($cache_id)) {
|
if (isset($varname)) {
|
||||||
$parent = $cache_id;
|
if (isset($this->config_vars[$varname])) {
|
||||||
$cache_id = null;
|
return $this->config_vars[$varname];
|
||||||
}
|
|
||||||
if (is_array($parent)) {
|
|
||||||
$data = $parent;
|
|
||||||
$parent = null;
|
|
||||||
} else {
|
} else {
|
||||||
$data = null;
|
return '';
|
||||||
}
|
|
||||||
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];
|
|
||||||
} else {
|
|
||||||
// create new template object
|
|
||||||
$tpl = new $this->template_class($template, $this->smarty, $parent, $cache_id, $compile_id);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// just return a copy of template class
|
return $this->config_vars;
|
||||||
$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;
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -350,11 +338,14 @@ class Smarty_Data extends Smarty_Internal_Data {
|
|||||||
public $parent = null;
|
public $parent = null;
|
||||||
// config vars
|
// config vars
|
||||||
public $config_vars = array();
|
public $config_vars = array();
|
||||||
|
// Smarty object
|
||||||
|
public $smarty = null;
|
||||||
/**
|
/**
|
||||||
* create Smarty data object
|
* create Smarty data object
|
||||||
*/
|
*/
|
||||||
public function __construct ($_parent = null)
|
public function __construct ($_parent = null, $smarty = null)
|
||||||
{
|
{
|
||||||
|
$this->smarty = $smarty;
|
||||||
if (is_object($_parent)) {
|
if (is_object($_parent)) {
|
||||||
// when object set up back pointer
|
// when object set up back pointer
|
||||||
$this->parent = $_parent;
|
$this->parent = $_parent;
|
||||||
@@ -363,7 +354,7 @@ class Smarty_Data extends Smarty_Internal_Data {
|
|||||||
foreach ($_parent as $_key => $_val) {
|
foreach ($_parent as $_key => $_val) {
|
||||||
$this->tpl_vars[$_key] = new Smarty_variable($_val);
|
$this->tpl_vars[$_key] = new Smarty_variable($_val);
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ($_parent != null) {
|
||||||
throw new Exception("Wrong type for template variables");
|
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