Re: HTML_QuickForm_Controller & DB & Smarty
| From: | Bertrand Mansion | Date: | Tue, 27 Jul 2004 17:33:12 +0000 |
| Subject: | Re: HTML_QuickForm_Controller & DB & Smarty | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13878@lists.php.net to get a copy of this message | ||
Stefan Ohrmann wrote:
>Hello,
>
>Am 27.07.2004 17:34 schrieb Julien Huang:
>> How can I build a form without using global variables for the database
>> and template engines ?
>
>You can use class members and setters.
>
>> /* ############################################# */
>> class Page_Add_Company extends HTML_QuickForm_Page
>> {
> var $db;
> var $tpl;
>
> // You can access the member var directly too,
> // via $page->db =& ...
> //
> // But i use set methods, like this two.
> function setDB(&$db)
> {
> $this->db =& $db;
> }
>
> function setTpl(&$tpl)
> {
> $this->tpl =& $tpl;
> }
>> function buildForm()
>> {
>
> //For simplicitiy i use the global vars as local vars
> //At most you will use $this->{varname}
> $db =& $this->db;
> $tpl =& $this->tpl;
>
> ...
>> }
>> }
>
>After page creation you can use the set methods to apply the template
>and the database.
>
>$page =& new Page_Add_Company;
>$page->setDB($db);
>$page->setTpl($tpl);
Actually, it would be cleaner to deal with everything that is template-related in the
'display' action directly.
You can also use "global $db, $tpl;"
Bertrand Mansion
Mamasam