Re: New thread - Template base class design

From: Date: Fri, 11 Jun 2004 03:34:12 +0000
Subject: Re: New thread - Template base class design
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-30465@lists.php.net to get a copy of this message
Paul M Jones wrote:
I'm skipping to the interesting part (for me).
ditto ;)
It does mean that one would have to set all vars singly ... unless setData() interfaced with the class vars themselves, not some sort of $vars array, e.g. ... function setData($array) {
    foreach ($array as $key => $val) {
        if ($key{0} != '_') {
            $this->$key = $val;
        }
    }
}
Another idea: if we provide a "fromObject" method that is like so: function fromObject($obj) {
    if (method_exists($obj, 'setTemplateData')) {
        $obj->setTemplateData($this);
    } else {
        foreach ($obj as $name => $value) {
            if ($name{0} == '_') {
                continue;
            }
            $this->$name = &$obj->$value;
        }
    }
} This will allow the passing in of an unrelated data object, and the template will instantly have access to all of the data. The possibilities are endless, as this is basically a runtime aggregation pattern combining the template's capabilities with the object's capabilities. You could also base your dataobject off the template's design through inheritance (which db_dataobject already can do - major plus, because your template vars are your database fields, makes debugging that much simpler) It also fully separates the business from the display logic even more than a series of "setData()" calls or "$tpl->var = $blah" calls. Greg

« previous php.pear.dev (#30465) next »