Jump to content

ZF Not Autoloading Custom Libraries/Classes


ryanlball@gmail.com

Recommended Posts

It seems like a simple thing.  My understanding is that as long as my library follows the same PERL naming convention and are placed in the include_path the classes should autoload.  So, specifically I want to autoload my models so I've included the 'application/models' in my include path like so:

 

set_include_path(implode(PATH_SEPARATOR, array(

get_include_path(),

    realpath(APPLICATION_PATH . '/../library'),

    realpath(APPLICATION_PATH . '/models'),

)));

 

This is almost identical to the default bootstrap file created by Zend_Tool.

 

Now, I have a class called 'ClientModel'.  In my index controller and action I'm trying to create a ClientModel object like so:

 

class IndexController extends Zend_Controller_Action

{

 

    public function init()

    {

        /* Initialize action controller here */

    }

 

    public function indexAction()

    {

        $client = new ClientModel();

    }

}

 

The model class looks like this:

 

class ClientModel extends Zend_Db_Table_Abstract

{

// .. Model code

}

 

Any ideas why this class is not auto loading?  I also have my own library that follows PERL naming that also doesn't load.  That library is located in the 'library' folder where the Zend Framework library is located. 

 

What's even more strange is that when I include the file directly as if it were in the model file, it loads correctly.  In other words, I have every reason to believe that the 'models' include directory is valid.  Also, Zend Library components load so it seems the autoloader is working.  Maybe there is something about the autoloader I don't know about?

 

Any thoughts are much appreciated!

In order for your simple example to work your ClientModel class would need to be named Client_Model and it would need to be within /models/Client/Model.php

 

You would then also need to add the Client namespace to your autoloader. eg;

 

$application = new Zend_Application(
    APPLICATION_ENV,
    array(
        'autoloaderNamespaces' => array('Client_'),
    )
);

 

Sorry, I should add. This is one way to do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.