From 65323da89d6e3b2ecaed04fa45eed35f67c28a11 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 29 Jan 2006 05:44:51 +0000 Subject: Changed how template controls initialize their properties. --- framework/Web/UI/TTemplateControl.php | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'framework/Web/UI/TTemplateControl.php') diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php index 72731ecd..79ada7d4 100644 --- a/framework/Web/UI/TTemplateControl.php +++ b/framework/Web/UI/TTemplateControl.php @@ -55,30 +55,17 @@ class TTemplateControl extends TControl implements INamingContainer private $_placeholders=array(); /** - * Constructor. - * Loads template for the control class if not loaded. - * Applies template directive if any. - */ - public function __construct() - { - if(($tpl=$this->getTemplate(true))!==null) - { - foreach($tpl->getDirective() as $name=>$value) - $this->setSubProperty($name,$value); - } - } - - /** - * @param boolean whether to attempt loading template if it is not loaded yet + * Returns the template object associated with this control object. * @return ITemplate|null the parsed template, null if none */ - public function getTemplate($load=false) + public function getTemplate() { if($this->_localTemplate===null) { $class=get_class($this); - $tpl=isset(self::$_template[$class])?self::$_template[$class]:null; - return ($tpl===null && $load)?$this->loadTemplate():$tpl; + if(!isset(self::$_template[$class])) + self::$_template[$class]=$this->loadTemplate(); + return self::$_template[$class]; } else return $this->_localTemplate; @@ -96,7 +83,7 @@ class TTemplateControl extends TControl implements INamingContainer } /** - * Loads and parses the control template + * Loads the template associated with this control class. * @return ITemplate the parsed template structure */ protected function loadTemplate() @@ -114,8 +101,12 @@ class TTemplateControl extends TControl implements INamingContainer */ protected function createChildControls() { - if($tpl=$this->getTemplate()) + if($tpl=$this->getTemplate(true)) + { + foreach($tpl->getDirective() as $name=>$value) + $this->setSubProperty($name,$value); $tpl->instantiateIn($this); + } } /** -- cgit v1.2.3