Categories
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.

Categories
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 pileofcrap.org 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 is.gd’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 pileofcrap.org can be on the top client list.

Categories
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:

<placemarks>
	<placemark>
		<name>Placemark 1</name>
		<latitude>-79.00</latitude>
		<longiude>42.00</longitude>
	</placemark>
	<placemark>
		<name>Placemark 2</name>
		<latitude>-129.00</latitude>
		<longiude>43.00</longitude>
	</placemark>
</placemarks>

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.

Categories
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') {
	$writer->setEnabled(true);
	$frontController->throwExceptions(true);
} else {
	$writer->setEnabled(false);
	$frontController->throwExceptions(false);
}

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

Categories
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…

Categories
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)
{
	Zend_Loader::loadClass('Zend_Filter_Inflector');
	$inflector = new Zend_Filter_Inflector(':action');
	
	$inflector->setRules(array(
   	 ':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
		$this->render('magic-content');
	} else {
		// no record, use my magic 404 thrower.
		$this->fileNotFound();
	}
}

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.