Extend Zend_View_Stream to easily escape view variables

Zend_View_Stream is used pretty much when ever you use Zend_View, and I’ve blogged about how handy it is before.  But as it’s a class like any other, you can extend it to give added functionality.  One such use is to add automatic escaping to your view variables when you want.  So instead of doing:

<?php echo $this->escape($this->var); ?>
<?= $this->escape($this->var); ?>

You could simply do:

<?=~ $this->var; ?>

That’s a lot simpler, isn’t it?
Continue reading “Extend Zend_View_Stream to easily escape view variables”

Did you like this? Share it:

Zend Framework hidden gems

Sometimes you come across hidden little gems in the Zend Framework that save you time, even if that’s just down to the amount of text you need to type. The Zend_View holds one of these little gems…

Did you know that you can use the short php open tags and echo tag in your view scripts, and you don’t even need to have this turned on in the php.ini file?

So you can have things like:

<? $this->viewHelper(); ?>


<?= $this->variable; ?>

instead of:

<?php $this->viewHelper(); ?>
<?php echo $this->variable; ?>

Might not seem a lot, but when you have a lot of view scripts to write then you can save quite a few key strokes.

It’s able to do this, even if you have short_tags off (as it should be!) because Zend_View uses a stream to open and seek through the view script – Zend_View_Stream.

Did you like this? Share it: