Re: HTML_QuickForm_Controller ActionDisplay class with Smarty

From: Date: Wed, 26 Jan 2005 09:16:56 +0000
Subject: Re: HTML_QuickForm_Controller ActionDisplay class with Smarty
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17164@lists.php.net to get a copy of this message
Hi, El mar, 25-01-2005 a las 18:17 -0800, Ed Greenberg escribió: > All of the $t->assigns that are "not in scope above" come from my main page > that is setting up the wizard. I need to get it into scope in the class. > I write only an "assign" in the renderForm method with all the form data (from example in docs): // assign array with form data $tpl->assign('form_data', $renderer->toArray()); My solution was to write a new class extending HTML_QuickForm_Action_Display with a new param ($tplfile) in the constructor to reutilize it. Then, all my calls are in this way: $page->addAction('display', new Base_Action_Display('insertPr.tpl')); I'm sure that this code can be improved, but this is mine :) The extended class: class Base_Action_Display extends HTML_QuickForm_Action_Display { var $tplFile; function Base_Action_Display ($tplFile){ $this->tplFile = $tplFile; } function _renderForm(&$pag) { // Create the template object $tpl =& new Smarty; // Create the renderer object $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl); $renderer->setRequiredTemplate( '{if $error} <span style="color:red">{$label}</span> <span style="color:red;font-size:smaller">*</span> {else} {$label} {if $required} <span style="color:red;font-size:smaller">*</span> {/if} {/if}' ); $renderer->setErrorTemplate( '{if $error}<span style="color:orange;font-size:smaller"> {$error}</span><br /> {/if} {$html}'); $pag->setRequiredNote( '<span style="color:red;font-size:smaller">*</span> <span style="color:black;font-size:smaller">Campo obligatorio.</span>'); // build the HTML for the form $pag->accept($renderer); // assign array with form data $tpl->assign('form_data', $renderer->toArray()); // parse and display the template $tpl->display($this->tplFile); } } I hope this is helpful for you. Toni. > </edg> >

« previous php.pear.general (#17164) next »