|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
gen Smarty n00b
Joined: 12 Dec 2007 Posts: 2
|
Posted: Wed Dec 12, 2007 9:23 am Post subject: Assign a object |
|
|
in latest smary version can b assigned to template
array ,string, int and so on
Code: |
function assign($tpl_var, $value = null)
{
if (is_array($tpl_var)){
foreach ($tpl_var as $key => $val) {
if ($key != '') {
$this->_tpl_vars[$key] = $val;
}
}
} else {
if ($tpl_var != '')
$this->_tpl_vars[$tpl_var] = $value;
}
} |
but if i have a full Object Oriented PHP code, the assign funciton have no use fore me.
suggestion to modife the assign function
Code: |
function assign($tpl_var, $value = null)
{
if (is_array($tpl_var)){
foreach ($tpl_var as $key => $val) {
if ($key != '') {
$this->_tpl_vars[$key] = $val;
}
}
}
else if (is_object($tpl_var)){
foreach (get_object_vars($tpl_var) as $key => $val) {
if ($key != '') {
$this->_tpl_vars[$key] = $val;
}
}
}
else {
if ($tpl_var != '')
$this->_tpl_vars[$tpl_var] = $value;
}
} |
|
|
Back to top |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Wed Dec 12, 2007 9:42 am Post subject: |
|
|
I don't think that's a good idea. To assign objects use register_object() or assign_by_ref().
FWIW, I think even assign() works fine with objects, even though they are copied eventually.
Boots, does COW in php apply to objects aswell?
If I assign an object to Smarty, I certainly don't want all its object variables assigned individually. I want the whole object with all its variables and methods. And .. what if I assign two objects of the same class to Smarty? In your solution all the variables of the first object will be overwritten by the second one. _________________ Darn computers always do what I tell them to instead of what I want them to do. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|