Category Archives: Zend Framework

Easy page scraping with Zend\Dom (from Zend Framework 2)

The other day I was interested in getting some information from the sussex.academia.edu site, specifically I wanted a list of tags for each of the faculty members. Now, this sounds relatively easy except when you consider that initial page contains a list of links to various schools/departments people have listed, and then under each of those pages you have different fieldsets with different types of people on them (and I was only interested in the faculty fieldset), and each person may or may not have tags and even then those tags may be hidden behind some javascript so that you click and view all of the tags… When you consider all of that you would be forgiven in thinking that it’s actually quite a daunting task!

Let me assure you, though, that by using Zend\Dom from the Zend Framework 2 library it’s actually a really simple task. In fact, I did it in around 20 lines of code.

So let’s start by looking at the code and then break it down a little more.

Continue reading Easy page scraping with Zend\Dom (from Zend Framework 2)

Did you like this? Share it:

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:

QrCode view helper

You see QrCodes popping up every now and again on sites, in publications and the like. I think they can be a very handy way for people with cameras on their phones to get a url or other content on to their phone very easily. (I’m thinking more about those people without iPhones or full keyboards, of course!)

If you’ve never seen a QrCode before, it looks something like this:

QR Code image

Now how cool would it be to be able to generate that automatically for each page on your site and allow people to be able bookmark that site on their phone? Well, I think it’d be pretty cool! So I came up with a very simple ZF view helper to do it for me.

Continue reading QrCode view helper

Did you like this? Share it:

Adding new items to RSS feed – it shouldn’t be this hard!

I have just started to use the Zend_Feed related components in earnest and am really liking the Zend_Feed_Writer (new to ZF 1.10.0). So what I wanted to do was created an RSS feed file is one didn’t exist and then keep updating that file as-and-when new items came in. Seems a really easy and simple thing to do, right? That, unfortunately, has not been my experience.

I have to say that to documentation seems quite lacking on the ZF site (for all the the Feed components, really, not just the Writer). Because of that, what follows may be idiotic and there really is an easy way. If so, I hope that you will post up a comment and let me know because I’d love to learn!

On with what I did…

Continue reading Adding new items to RSS feed – it shouldn’t be this hard!

Did you like this? Share it:

Zend_Form decorators webinar

If you’re not sure about Zend_Form’s decorators, what they are or how to use them, then Matthew Weier O’Phinney has the webinar for you:

http://www.zend.com/webinar/Framework/webinar-leveraging-zend_form-decorators-20091216.flv

It’s a great introduction to decorators, how to implement them and how to do slightly more complex things with them. Well worth a watch!

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(); ?>

and:

<?= $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:

Shorten urls automatically with a Zend Framework filter

I think we can all agree that URL shortening services are great and are very handy to tidy up those long and obnoxious links. However, a lot of the time people simply forget to use them, or often don’t know about them in the first place. I’ve noticed this in a blog system I wrote using Zend Framework. On one hand I love that people post messages, but on the other it annoys me that they may supply a link that is so long it breaks the formatting of the page, or looks just plain ugly.

So what are my options? I could train everyone who posts blogs on the system to use a url shortening service or I could manually tweak all the links myself. As solutions they are not very practical at all; I don’t have the time to change any/all links myself, and I certainly don’t have enough patience to train everyone! So an automatic way of doing things is needed, and the filtering in Zend Framework comes to the rescue!

Continue reading Shorten urls automatically with a Zend Framework filter

Did you like this? Share it:

Quick and easy email encoding view helper

Here’s a quick and easy view helper for Zend Framework that will encode an email address. It will encode just an email address or return a whole mailto link. The encoding is basically the same as in the Smarty template engine.

Obviously there’s a lot of room for improvement; javascript encoding, representation as an image, and so on… but then it wouldn’t be quick an easy – it’d be slightly longer and just a little more complex. 😉

Continue reading Quick and easy email encoding view helper

Did you like this? Share it:

Zend Framework 1.6RC1

If you haven’t heard already, Zend Framework 1.6RC1 is out and has lots of interesting new features. Finally there’s a SOAP component (seemed odd to me to have an enterprise-level framework without it!) There’s also a paginator, XML configs can have attributes, Dojo integration and lots more.

It’s been out for about 10 days as of the time I write this, but the only new thing I’ve tried as of yet is the Zend_Paginator component. And I must say that I am very happy with how easy it was to set up and integrate in to a site… Essentially, I just had to pass my select object to the paginator and write a view partial to handle how it looked – it was that easy! With the output of the pagination put in to a partial it makes the whole thing very easy to rebrand and configure to exactly how you want it to look. This is definitely a component I’m going to be using a lot.

Looking forward to using the other new features, too. There is a Zend Webinar to show the new features of ZF1.6 coming up on the 13th August, 2008. Also one in September to go over integrating the new Dojo features.

Did you like this? Share it: