Coding PHP Zend Framework

Zend Framework 1.7.5 Released

Zend Framework 1.7.5 was released just a short while ago.  While there’s not much with regards to features, there’s an interesting update to the view renderer and local file injection attacks.

I’m guilty of using this style of inclusion in some cases.  Sometimes it’s just easier. I guess it’s time to re-think how I do what I do in these very few and rare cases.  No more ‘../’ in my render statements!

Thanks to Zend Framework In Action for the quick update.

Coding Zend Framework

Using Zend Framework to update Twitter

I was reading a post over on Mashable about the most popular twitter clients and I found it somewhat fascinating.  As of the somewhat recent Zend Framework 1.7 release, there was a new service added. Zend_Service_Twitter  – which gave me a few ideas on what to do with my own twitter account and actually feed it some information.

One thing I’m going to do, is with the new rewrite of is to have users be able to auto-update their twitter when they post a new article or photo to their highly improved PoC Blog thing.  Thanks to Zend it’s pretty simple:

$twitter = new Zend_Service_Twitter($user, $pass);
$twitter->status->update('This is my new update');

And it’s done.  Used in conjunction with tinyurl or’s APIs I can automatically do micro-updates to twitter and have all the followers of all my users automatically be notified of the new content.  It’s pretty slick, huh?

Maybe someday can be on the top client list.

Coding PHP Zend Framework

Why is XML Such a Pain in JavaScript?

Why is it that when one tries to parse some fairly simple xml:

		<name>Placemark 1</name>
		<name>Placemark 2</name>

For example, iterating through all the placemarks and extracting the names, lats and longs using javascript is a very tedious affair. In fact, I’ve found it almost pointless to even try without my head exploding.

Coding PHP Zend Framework

Zend Framework, FireBug, FirePHP and Debuggin’

I finally got around to implementing some debugging my applications. By debugging, I mean something more useful than random ‘echo‘ and ‘exit‘ statements littering my code.

I found a nice post by Christoph Dorn with a few nice pointers on how to integrate FireBug and FirePHP using Zend_Log and Zend_Log_Writer_Firebug.

My only addition was the use of a ‘debug’ flag that I use in my applications.  Basically, if it is set to true the logwriter will work, if it’s false, it won’t write anything.

if ($config->debug === '1') {
} else {

That little snippit in my bootstrap makes all the magic happen.

PHP Zend Framework

Rendering Loops, the Easy Way

I’d like to say I’m an idiot and should have known how to do this a long long time ago, but since the Zend Framework is so huge – I’m letting it slip by.

Normally I’ve always rendered repetitive data by using a foreach on my objects or arrays and then within that foreach I usually render an external file (when I’m not lazy), or even just have a large chunk of html within my view scripts.  When it comes to bigger sites, I want the html fragments to be as simplified and manageable as possible…

Coding PHP Zend Framework

Using __call() in your controller to render magic content.

I was writing a basic CMS-type system and I was getting a bit annoyed with long urls, ie: /index/content/page/something, when I really just wanted /content/something – so I thought to myself, “self, why don’t you use __call() and just magically handle the incoming actions?

Well, self, that was a brilliant idea.

function __call($method, $params)
	$inflector = new Zend_Filter_Inflector(':action');
   	 ':action'  => array('Word_CamelCaseToDash', 'StringToLower'),

	$magicAction = str_replace('-action', '', 
		$inflector->filter(array(':action' => $method)));

	/* TODO: lookup the magicAction in the cms table
	 * replace in_array with a check for the db_row
	 * remove $magicArray
	$magicArray = array('in-person', 'custom-experience');
	if (in_array($magicAction, $magicArray)) {
		// we have a record
	} else {
		// no record, use my magic 404 thrower.

And with that, any of non-existent actions requested in my controller will be looked up in a db, then rendered using a common view script.  Pretty simple, really.