Re: HTML_QuickForm_Controller & DB & Smarty
| From: | Stefan Ohrmann | Date: | Tue, 27 Jul 2004 16:39:19 +0000 |
| Subject: | Re: HTML_QuickForm_Controller & DB & Smarty | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13877@lists.php.net to get a copy of this message | ||
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);
regards
Stefan