Adding a custom resource type to the Zend Framework autoloader

Home / PHP / 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 http://pietervogelaar.nl/ 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.

One Comment

Leave a Reply

%d bloggers like this: