Zend Framework: Zend_View_PhpTal Component Proposal
| Proposed Component Name | Zend_View_PhpTal |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_View_PhpTal |
| Proposers | Matthew Ratzloff |
| Revision | 0.2 - September 12, 2007 (wiki revision: 14) |
Table of Contents
1. Overview
Zend_View_PhpTal is an implementation of Zend_View_Interface for the PHPTAL templating engine.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
Handle calls to the PHPTAL engine as transparently as possible for basic operations.
4. Dependencies on Other Framework Components
- Zend_View_Interface
- PHPTAL
5. Theory of Operation
Implement basic functionality while letting calls to getEngine() handle more advanced concepts (macros, etc.).
6. Milestones / Tasks
- Milestone 1: [DONE] This proposal
- Milestone 2: [DONE] Working implementation
- Milestone 3: Unit tests exist, work, and are checked in.
- Milestone 4: Documentation
7. Class Index
- Zend_View_PhpTal
8. Use Cases
Works like Zend_View. Additional functionality is self-explanatory. See full code below.
9. Class Skeletons
Labels:
5 Comments
comments.show.hideDec 08, 2006
Matthew Weier O'Phinney
Matt – when you document this, and also in the class-level docblock, please put a notice that phptal is licensed under the LGPL and that users should only use the wrapper and phptal when their project license will not conflict with the LGPL.
Otherwise, looks good!
Jan 31, 2008
Iván Montes
Matt,
First of all thank you for your work on this class, I was thinking about implementing it when I found it
What would you thing of changing __get() to the following:
if ($this->__isset($key)) { if (is_array($this->_variables[$key])) { return new ArrayObject($this->_variables[$key]); } return $this->_variables[$key]; } return null;This change (returning an ArrayObject for array variables) allows to have read-write access on the variable when accessing it from the view object. Like in the following example:
I guess it's not the fastest code but it's quite convenient.
Besides, setting a variable starting with an underscore ('_') just silently ignores the action. I think it should throw an exception to notify the developer. Moreover, the assign() method does not even check for the underscore which could result on a exception being thrown from Phptal at render time, since the variables are actually passed over then.
Just a last thing. Why are the script paths using 'templates' as the default folder name instead of 'scripts'? Is it intended or just a left over from previous ZF versions?
cheers,
Iván
Feb 02, 2008
Matthew Ratzloff
Hi Iván,
Most of those methods were copied and modified from Zend_View_Abstract as it existed at the time this was originally written. If this proposal were to be resurrected it would be updated to match whatever Zend_View looks like currently.
As far as the "templates" name, that was specific to my use at the time and I forgot to update it.
May 10, 2009
Mario Gehnke
Is this proposal dead? I hope not! I'm looking forward to see such a component..
Jun 14, 2009
Marek
I have modified Your code to extend Zend_View_Abstract. Unfortunately there is no english version in this moment so You have to use translator (comments are in English, I'll try to rewrite it soon).
PHPTAL View (Zend_View_Abstract)
Gtranslate has some problems with valid syntax so please refer to original text.
Article contains examples both with Zend_Application and standard aproach. Additionaly `helper:` modifier is available inside templates (e.g. <a tal:attributes="href helper:url(array('username' => 'martel'), 'user'))">Martel</a>), templates could be gzipped and correct headers are set (because ZF does not have any Zend_Client class i put my own My_Browser class).