Re: New thread - Template base class design
| From: | Paul M Jones | Date: | Fri, 11 Jun 2004 02:43:00 +0000 |
| Subject: | Re: New thread - Template base class design | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-30461@lists.php.net to get a copy of this message | ||
I'm skipping to the interesting part (for me).
On Jun 10, 2004, at 9:22 PM, Greg Beaver wrote:
I would recommend that the assignment question be studied very carefully - Alan's method solves the extract() problem elegantly. If template variable assignment simply meant <?php $tpl = &Template::create('flexy'); $tpl->t = $data; $tpl->thing = &$refdata; ?> and the template in savant would simply reference $this->t and $this->thing. Other templates would compile so that {t} became $this->t, and so on.Hey, that's pretty nice! Has that been there all this time? It hasn't been clear to me at all it worked that way in Flexy, and I've been working through the code line by line. 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; } } } ... if we even kept the setData() method at all. I think we should for convenience, if no other reason.
This would allow very straightforward management. It would mean that ALL private/protected variables would have to be prefaced with _ to avoid overwriting, but that's not a big deal.No, no, that's beautiful: simple, elegant, straightforward.
In any case, the important thing is direct assignment to members of the template is probably the way to go - it's efficient, direct, and really easy to document.Completely agreed. I'll rework my example implementation tomorrow morning; by then, Alan will have had at least 8 hours to knock me back and forth while I sleep. :-)
In PHP5, __set() could be used to validate template assignment as well, which is a neat by-product of this design choice.Yes, really cool. :-) -- Paul M. Jones Savant: the simple alternative to Smarty for PHP. http://phpsavant.com/ DB_Table: build RDBMS tables and XHTML forms in one PHP class. http://wiki.ciaweb.net/yawiki/index.php?area=DB_Table Yawiki: your collaborative online documentation system. http://yawiki.com/ Yawp: a single-file foundation for PHP applications. http://phpyawp.com/