Archive for the ‘php’ Category

Zend Framework 1.7.5 Released

Sunday, February 22nd, 2009

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.

Why is XML Such a Pain in JavaScript?

Saturday, February 7th, 2009

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.

(more…)

Zend Framework, FireBug, FirePHP and Debuggin’

Sunday, February 1st, 2009

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.

Geocodes Made Easy

Saturday, January 24th, 2009

Using my Google Maps API key I can geocode almost anything*.

And with Zend Framework, it’s f’n damn simple!

Zend_Loader::loadClass('Zend_Rest_Client');
$rest = new Zend_Rest_Client('http://maps.google.com/maps/geo');
//?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=json&oe=utf8&sensor=true_or_false&key=your_api_key

$rest->key('YOUR_API_KEY');
$rest->q('1600 Amphitheatre Parkway, Mountain View, CA');
$rest->output('xml');
$rest->oe('utf8');

$result =  $rest->get();
// the whole $result is a SimpleXML object
print_r((string)$result->Response->Placemark->Point->coordinates);

And that’s it.  Save the results someplace useful so you don’t have to hammer the shizzle out of Google (there are query limitations per key).

* I mean almost anything, because you cannot geocode a UK Postal Code, because the Queen and her Royal Mail owns the copyrights on it. Silly, I know.

Rendering Loops, the Easy Way

Tuesday, January 20th, 2009

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…

(more…)