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/TPage.php | 9 ++++----- framework/Web/UI/TTemplateControl.php | 31 +++++++++++-------------------- 2 files changed, 15 insertions(+), 25 deletions(-) (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index 28f1b036..a5e4fa52 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -111,11 +111,13 @@ class TPage extends TTemplateControl private $_previousPagePath=''; /** - * Constructor, overrides parent implementation. Parent constructor called in initializeProperties. + * Constructor. + * Sets the page object to itself. */ public function __construct() { - + parent::__construct(); + $this->setPage($this); } /** @@ -125,15 +127,12 @@ class TPage extends TTemplateControl public function initializeProperties($initProperties=null) { Prado::trace('Constructing page','System.Web.UI.TPage'); - $this->setPage($this); if(is_array($initProperties)) { Prado::trace('Initializing page properties specified in configurations','System.Web.UI.TPage'); foreach($initProperties as $name=>$value) $this->setSubProperty($name,$value); } - //ask template control to initialize - parent::__construct(); } /** 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