Pragmatism in the real world

Remove index.php from your URL

One thing you may have noticed with Zend Framework projects that use the baseUrl() view helper to reference CSS and other static files is that it doesn't work if the URL contains contains index.php. Let's explain, by using code from the tutorial. In the layout.phtml file, we link to a CSS file like this: <?php echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/site.css'); ?> This code uses a baseUrl() view helper that looks like this <?php class Zend_View_Helper_BaseUrl { function baseUrl()… continue reading.

PHPUK 11 Conference in London

PHPUK, the conference organised by the PHP London usergroup is being held on Friday 25th February 2011. If you haven't bought your ticket yet, then you should! I'll be there talking about optimising a Zend Framework application, which should be interesting. I'm going to be looking at what's slow in the ZF code itself and have been profiling using xhprof which is the first time I've used it. It's quite good, once you have it… continue reading.

Enrise: Using MemCacheQ as a Message Queue

Tim de Pater of Enrise has written a new article on how to integrate MemCacheQ with Zend Framework application using Zend_Queue_Adapter_Memcacheq component: For www.nd.nl (a Dutch newspaper) we wanted a simple and free queue mechanism that integrates with Zend Framework for handling a number of jobs. We found MemcacheQ. The article then goes through how to run the memcacheq daemon and then shows the PHP code to add a job to the queue and then… continue reading.

Displaying an RSS feed in WordPress

My wife decided that she wanted to display a list of her latest AudioBoos in the sidebar of her blog. She looked at the AudioBoo JavaScript widget but decided it wasn't subtle enough and so she enlisted me to solve her problem. It turns out that AudioBoo has an RSS feed, so a simple plugin was required. I had a quick look on the extension site, but most are now "widgets" which her theme isn't… continue reading.

2010 in pictures

Another year is over, and as is becoming a tradition, I like to show off some photos that recap my year!\ January We started the year with a visit to the zoo! There was also snowy weather last January and on the last day of the month, we put our house on the market. We would be accepting an offer on it in late October. February In February, I took pictures of canal boats. The… continue reading.

Handling exceptions in a Front Controller plugin

If you have a Zend Framework Front Controller plugin which throws an exception, then the action is still executed and then the error action is then called, so that the displayed output shows two actions rendered, with two layouts also rendered. This is almost certainly not what you want or what you expected. This is how to handle errors in a Front Controller plugin: Prefer preDispatch() over dispatchLoopStartup() as it is called from within the… continue reading.

David Papadogiannakis: HTML5 Zend Framework form elements

David Papadogiannakis has posted a new article on the new features for forms with HTML5 and how it applies to Zend Framework's Zend_Form component. HTML4 had a few different input elements that could be added to your form : text, password, hidden, checkboxes etc. HTML5 brings even more types that can be added to your <input> tag. He then goes on to provide an override to Zend_Form_Element_Text showing how to use the new attributes with… continue reading.

View helpers in modules

I came across a situation last week where I needed to access a view helper that was in the default module's views/helpers directory when I was in another module. This came about because my layout.phtml uses a view helper that is in application/views/helpers. By default, it doesn't work and you get an error along the lines of: Plugin by name 'LoggedInAs' was not found in the registry; used paths: Plan_View_Helper_: /www/funkymongoose/habuplan/application/modules/plan/views/helpers/ Zend_View_Helper_: Zend/View/Helper/ The fix… continue reading.

PHP 5.3 is quicker than PHP 5.2

I know that everyone already knows this, but I happened to find out for myself recently! I was looking at the way view helpers work in ZF2 and thought it would be more convenient if we altered the syntax a little. A side-effect of the change was that we'd have to use call_user_func_array, which is perceived as slow. I thought I'd whip up a simple test to find out how much slower it would be… continue reading.

Local config files and Zend_Application

A friend of mine recently had a requirement where she wanted to have two config files loaded into Zend_Application, so that the specific settings for the server were not stored in the version control system. Hence she has two config files: application.ini and local.ini where local.ini is different on each server. Update: As takeshin points out with ZF 1.10 or later, an easier solution to this is to pass both ini files into Zend_Application: $application… continue reading.