Adding a custom resource type to the Zend Framework autoloader

Because I can never remember how to do this and because it’s not that easy to find on google I have copied the info here.

If you want to add a folder to the application directory and then have classes within that directory autoload, for instance you add a folder ‘objects’ (application/systems) that contain classes like Application_System_One. This would work for any Application_ classes and its exactly what the Zend Framework autoloader does when it inits the default resorces like application forms, models, services etc.

Here’s what you need to do:

Full credit goes to for this copy and paste.

This week I wanted to created the folder “application/grids/” to store my grids in. For example the path to the grid is “application/grids/Product.php”.
The code inside this PHP file:

You will now get the error “Fatal error: Class ‘Application_Grid_Product’ not found”. The new path must be added to the Zend Autoloader in order to load the required classes. Your bootstrap must look like this:

And you’re done! It would be even nicer to configure this in the application.ini, but unfortunately there is no way to add a resource type trough the application.ini at the moment.

PHP MSSQL & PDO_DBLIB (FreeTDS) support on Mac OSX 10.9 Mavericks

So since upgrading to Mavericks I have lost the ability to use PHP’s MSSQL and PDO_DBLIB database extensions. I had previously set this up on Lion/Mountain Lion.

You’ll need to download the latest Xcode from the Mac App Store and then run it and install the command line tools. This will allow you to build the packages below.

We’ll also need autoconf so download the latest source at autoconf-latest.tar.gz. At the time this article was published the latest release was v2.69.

Extract this and then using terminal navigate to the extracted source directory and run the below commands:

Now on to FreeTDS, this is the library that will connect to MSSQL. Visit this link to get the latest stable version of FreeTDS: freetds-stable.tgz.
At the time this article was published the latest stable release was v0.91.

Once it’s downloaded and extracted, again in terminal, navigate to the the extracted directory. Now enter the below commands to build and install the driver.

Hopefully that all went well and there were no errors.

Now its time to build the PHP MSSQL and PDO_DBLIB extensions. Use the link below to download the Mavericks PHP source from Apple and then extract the archive.
php-5.4.17.tar.bz2 from Apple

To build and install the MSSQL extension, in Terminal change to the new MSSQL extension directory (php-5.4.17/ext/mssql) and run the below commands to build the mssql extension.

To build and install the PDO_DBLIB extension, in Terminal change to the new PDO_DBLIB extension directory (php-5.4.17/ext/pdo_dblib) and run the below commands to build the pdo_dblib extension.

Now that thats done all we need to do is make changes to the php.ini file so that the extensions are enabled. The file we need to edit is /etc/php.ini, if your system doesn’t have this file then lets create it from the default one.


Ok so at this stage we can edit the /etc/php.ini file, as there are many ways to do this I will describe the process rather than listing commands.

  • Open /etc/php.ini in your favourite text editor with root privileges
  • Search for the line ; extension_dir = "./"
  • Replace the above line with extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20100525/"
  • Search for the line ;extension=php_zip.dll
  • Below this line add these two lines:
  • Save the file and exit

The changes will be immediate for PHP CLI but if you are using PHP with Apache you will need to restart Apache (sudo apachectl restart).

Hope it works for you…

Using syslog for your PHP application logging

In the past I have created custom log files for my PHP applications, mainly because I’d never bothered to read up on syslog and I wasn’t using it for major stuff.

This time I decided to do the reading and syslog really does have lots of benefits and is just as quick to set up as custom logging.

Anyway, I found this nice overview and examples of how you can use syslog with your application.

Check it out – Using syslog for your php applications

Looking back

It’s been a good while since my last post and as I look back over the posts I’ve made I realise that in only one post have I actually talked about coding. The post I am talking about is the one on using PHP and Curl to login to a website to download content. The rest of the posts have been about troubles I’ve had while setting up my dev environment on OSX lion.

While this info has already been useful to some people and probably will continue to help people it wasn’t really the reason that I set up the blog. As I learnt new things I wanted to share them but unfortunately due to various things (one being a new role) I have been very busy and haven’t had the time or the content to post.

As a newly appointed development manager I feel that this blog might end up going a different direction to the original plan.

One post I do hope to make soon is related to recruitment of PHP developers. This seemingly simple task has proved challenging and I feel I have some advice to give anyone going through the process.

PHP memcached on OSX Lion

Having set up the PHP memcache extension on my mac yesterday I now need the PECL memcached extension to use with Zend_Cache. This one was a little more involved than yesterday so here is a quick list of things you’ll need to do.

My first instinct was to use PECL to get the extension but doing that told me that there was an unmet dependancy so it couldn’t be installed. The missing dependancy was libmemcached, here’s what you need to do to get libmemcached setup:

First go to and download the latest libmemcached (1.0.4 at the time of writing), once downloaded extract the archive and then open up a terminal window and cd to the new libmemcached-1.x.x directory. Now enter the commands below into the terminal window one at a time.

These commands will each take some time to run and while they are running you will see lots of output in the terminal window. What these commands do are ./configure configures the package for your system, make compiles the code into a binary that is usable by the system and sudo make install installs the built files onto your system (which in this case is moving the libmemcached library into place on your system).

Now that we have solved the dependancy issue we can now run PECL again:

At the end of this process the script will remind you to configure PHP to use the new extension, if you are unsure on how to do this you can follow the end of yesterdays post – but dont forget to use memcached instead of memcache.

PHP memcache extension on OSX Lion

Today I needed the PHP memcache extension on my Mac OSX Lion 10.7.3 development machine for a project I’m working on. I was pleased to find out that this was a nice and easy one to get up and running.

Open up a terminal window and run the command below, this will tell PECL to download, build and install the extension.

Now that the extension is installed on your system, you need to enable it in your PHP configuration file. On a standard system the php.ini file can be found at /etc/php.ini. Open the file and scroll down to the extensions section, at the bottom of this section add the line and then save and close the file.

After that, all that is required is for you to restart Apache and enjoy your new extension

Using PHP and CURL to log in to a website

The other day I wanted to automate some downloading from a username and password secured website. I wrote a quick script and it is working like a dream, below is the CURL part of the code that does the logging in and download.