ryanlball@gmail.com Posted December 29, 2009 Share Posted December 29, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/186632-zf-not-autoloading-custom-librariesclasses/ Share on other sites More sharing options...
trq Posted December 29, 2009 Share Posted December 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186632-zf-not-autoloading-custom-librariesclasses/#findComment-985702 Share on other sites More sharing options...
ryanlball@gmail.com Posted December 30, 2009 Author Share Posted December 30, 2009 I see. So it sounds like auto including files needs to be within a name space. Is there a way to auto include classes that are simply in the include_path but not necessarily in a name space? Quote Link to comment https://forums.phpfreaks.com/topic/186632-zf-not-autoloading-custom-librariesclasses/#findComment-985723 Share on other sites More sharing options...
trq Posted December 30, 2009 Share Posted December 30, 2009 I'm not sure. Ive always put my models and all other class within a /library/Projectname directory, then made a Projectname_ namespace and gone from there. eg; My models end up being name something like... class Projectname_Model_Foo Quote Link to comment https://forums.phpfreaks.com/topic/186632-zf-not-autoloading-custom-librariesclasses/#findComment-985728 Share on other sites More sharing options...
ryanlball@gmail.com Posted December 30, 2009 Author Share Posted December 30, 2009 I see. Thank you for your help on this!! I'll probably just do something similar. Thank you again! Quote Link to comment https://forums.phpfreaks.com/topic/186632-zf-not-autoloading-custom-librariesclasses/#findComment-985749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.