Re: [rwfphp-developers] MultiContainer
Status: Beta
Brought to you by:
kaibab
|
From: Renaun E. <re...@rw...> - 2004-09-13 17:14:58
|
Nice to hear from you, Berend Dekens wrote: > Hi, > > I finally got back to my projects and I think I know what is going > wrong... I tried to build a control that contains multiple other > controls but only displays one at a time. This way I can design a skin > with only one variable in the Smarty template that switches controls > depending on what the user is doing. (Perhaps this can be done in > another way but I thought the easiest way was to simply switch between > controls). > I usually create a variable that is a folder value. Then if i want different skin i just change the varible the different folder would have the different skins. Something like: ($folderName = 'skin1';) templates/skin1 templates/skin2 templates/skin3 etc... $this->TemplateFile = 'templates/'.$folderName.'/templateFile.rwf.tpl'; Each skin folder has the same templates with the same names that map into the Controls, but the html/Smarty code is different. Now for your code: For starters I would take a look at http://www.rwfphp.org/rwfdoc/rwfPHP/Control.html#var$Controls This inherited object contains some properties and methods we can use. I couldn't find the source of the problem right off the back, so I think if we make some changes we might see something different happen. My changes are below: > <?php > require_once(RWF_DIR.'rwf/Web/UI/WebControls/WebControl.class.php'); > class MultiContainer extends WebControl { > var $controls; var $controlsByNumber > var $select; > function MultiContainer() { > WebControl::WebControl(); > $this->controls = array(); > $this->select = 0; $this->controlsByNumber = array(); > } > function addControl(/* Control */ $control) { > $this->controls[count($this->controls)] = &$control; > } function addControl($control) { $this->AddControls($control->Name,&$control); $this->controlsByNumber[count($this->controlsByNumber)] = &$control; } > function setVisible(/* number */ $n) { > if (!is_numeric($n)) return $this->setVisibleByName($n); > if ($n >= 0 && $n <= count($this->controls) - 1) { > $this->select = $n; } > } function setVisible($n) { if(!is_numeric($n)) return $this->setVisibleByName($n); if($n >= 0 && $n <= count($this->controlsByNumber) - 1) { $this->select = $n; } } > function setVisibleByName($name) { > for ($i = 0; $i < count($this->controls); $i++) { > if ($this->controls[$i]->Name == $name) return > $this->setVisible($i); } > } function setVisibleByName($name) { // $this->Controls is from the Control class if(isset($this->Controls[$name])) return $this->Controls[$name]; else // Handle error here } > function GetTemplate($smarty) { > if (count($this->controls) == 0) return "[Empty container]"; > return > $this->controls[$this->select]->getTemplate($smarty); } > /*function ConstructName() { > if (count($this->controls) != 0) return > $this->controls[$this->select]->ConstructName(); }*/ > } > function GetTemplate($smarty) { if(count($this->controlsByNumber) == 0) return "[Empty container]"; return $this->controlsByNumber[$this->select]->GetTemplate($smarty); } > ?> > > Hope we can sort this out. > > Berend Dekens > aka Cyberwizzard > The problem might be with the use of $controls in the MultiContainer, its not good (an easy to do with php) to override the Properties of the rwfphp classes. Overriding methods is less problematic and some methods like GetTemplate are made to be overridden, but always be careful about doing it. Here is the code in one piece: <?php require_once(RWF_DIR.'rwf/Web/UI/WebControls/WebControl.class.php'); class MultiContainer extends WebControl { var $controlsByNumber; var $select; function MultiContainer() { WebControl::WebControl(); $this->controlsByNumber = array(); $this->select = 0; } function addControl($control) { $this->AddControls($control->Name,&$control); $this->controlsByNumber[count($this->controlsByNumber)] = &$control; } function setVisible($n) { if(!is_numeric($n)) return $this->setVisibleByName($n); if($n >= 0 && $n <= count($this->controlsByNumber) - 1) { $this->select = $n; } } function setVisibleByName($name) { // $this->Controls is from the Control class if(isset($this->Controls[$name])) return $this->Controls[$name]; else // Handle error here } function GetTemplate($smarty) { if(count($this->controlsByNumber) == 0) return "[Empty container]"; return $this->controlsByNumber[$this->select]->GetTemplate($smarty); } ?> ps - I would prefer that you would not swear while posting to the list. |