Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.