(on Friday, 29 October 2010, 10:17 PM +0100):
> On 2010-10-29 5:51 pm, Matthew Weier O'Phinney wrote:
> >-- chikaram<chikara.miyake@gmail.com> wrote
> >(on Friday, 29 October 2010, 06:23 AM -0700):
<snip>
> I don't know about the *only* way... What I did for a bit of an
> experiment was to extend the Zend_View_Stream class and override the
> stream_open method. It was essentially exactly the same, except
> that I added this before the conversion of short tags to long:
>
> $this->_data = preg_replace(
> '/\<\?\=~ (.*?);? \?>/',
> '<?php echo $this->escape($1); ?>',
> $this->_data
> );
>
> Then all that had to be done was to register the zend.view stream
> wrapper before I knew ZF did:
>
> stream_register_wrapper('zend.view', 'MyStream');
>
> and in any views I just had to do:
>
> <?=~ $this->foo; ?>
>
> Of course, it introduced a non-standard php tag in to the views, but
> it was OK in this instance because 1) it was just an experiment, and
> 2) the code was for wholly in-house applications and none of it
> distributed, so I didn't really have to worry about compatibility,
> short tags, non-standard php tags, etc. But it did work like a
> charm!
That's a _really_ elegant solution, and a perfect use of stream
wrappers. Nice work!
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
没有评论:
发表评论