+ Reply to Thread
Results 1 to 3 of 3

Thread: Zend_Application_Module_Autoloader cannot find my models

  1. #1
    djcoder is offline Junior Member
    Join Date
    Apr 2009
    Posts
    10

    Question Zend_Application_Module_Autoloader cannot find my models

    I am using 1.10.2 and after reading the documentation(see The Module Resource Autoloader near the end). I thought that the autoloader would be able to find my models within each module by calling
    Code:
    $model = new Admin_Model_Event();
    However this caused a class not found error.

    For now I manually told it using a _init resource in the bootstrap:
    Code:
    $resourceLoader = new Zend_Loader_Autoloader_Resource( array(
    	'namespace' => '',
    	'basePath'  => APPLICATION_PATH ));
    		
    $resourceLoader->addResourceType( 'model', 'modules/admin/models/', 'Model' );
    $resourceLoader->addResourceType( 'dbtable', 'modules/admin/models/DbTable/', 'DbTable' );
    This is not an elegant solution as I would have to manually list an equivalent for every module.

    Just to be sure I dumped the autoloader
    Code:
    <?php
    class Admin_IndexController extends Zend_Controller_Action
    {
    	public function init()
    	{
    		/* Initialize action controller here */
    	}
    
    	public function indexAction()
    	{
    		$loader = Zend_Loader_Autoloader::getInstance();
    		die( print_r( $loader->getAutoloaders() ));
    	}
    }
    and received:
    Code:
    Array
    (
        [0] => Zend_Loader_Autoloader_Resource Object
            (
                [_basePath:protected] => /...../intranet/webapp/application
                [_components:protected] => Array
                    (
                        [Model] => /...../intranet/webapp/application/modules/admin/models
                        [DbTable] => /...../intranet/webapp/application/modules/admin/models/DbTable
                    )
    
                [_defaultResourceType:protected] => 
                [_namespace:protected] => 
                [_resourceTypes:protected] => Array
                    (
                        [model] => Array
                            (
                                [namespace] => Model
                                [path] => /...../intranet/webapp/application/modules/admin/models
                            )
    
                        [dbtable] => Array
                            (
                                [namespace] => DbTable
                                [path] => /...../intranet/webapp/application/modules/admin/models/DbTable
                            )
    
                    )
    
            )
    
        [1] => Zend_Application_Module_Autoloader Object
            (
                [_basePath:protected] => /...../intranet/webapp/application
                [_components:protected] => Array
                    (
                        [Model_DbTable] => /...../intranet/webapp/application/models/DbTable
                        [Model_Mapper] => /...../intranet/webapp/application/models/mappers
                        [Form] => /...../intranet/webapp/application/forms
                        [Model] => /...../intranet/webapp/application/models
                        [Plugin] => /...../intranet/webapp/application/plugins
                        [Service] => /...../intranet/webapp/application/services
                        [View_Helper] => /...../intranet/webapp/application/views/helpers
                        [View_Filter] => /...../intranet/webapp/application/views/filters
                    )
    
                [_defaultResourceType:protected] => model
                [_namespace:protected] => 
                [_resourceTypes:protected] => Array
                    (
                        [dbtable] => Array
                            (
                                [namespace] => Model_DbTable
                                [path] => /...../intranet/webapp/application/models/DbTable
                            )
    
                        [mappers] => Array
                            (
                                [namespace] => Model_Mapper
                                [path] => /...../intranet/webapp/application/models/mappers
                            )
    
                        [form] => Array
                            (
                                [namespace] => Form
                                [path] => /...../intranet/webapp/application/forms
                            )
    
                        [model] => Array
                            (
                                [namespace] => Model
                                [path] => /...../intranet/webapp/application/models
                            )
    
                        [plugin] => Array
                            (
                                [namespace] => Plugin
                                [path] => /...../intranet/webapp/application/plugins
                            )
    
                        [service] => Array
                            (
                                [namespace] => Service
                                [path] => /...../intranet/webapp/application/services
                            )
    
                        [viewhelper] => Array
                            (
                                [namespace] => View_Helper
                                [path] => /...../intranet/webapp/application/views/helpers
                            )
    
                        [viewfilter] => Array
                            (
                                [namespace] => View_Filter
                                [path] => /...../intranet/webapp/application/views/filters
                            )
    
                    )
    
            )
    
    )
    I am sure there is a simple way to inform Zend it needs to look inside the "modules" folder for it's resource mappings not just the "application" folder.

    Look forward to getting over this issue.

    Thank you for your help.

  2. #2
    alokin is offline Senior Member
    Join Date
    Apr 2009
    Posts
    192

    Default

    If Bootstrap class of some of your modules extends Zend_Application_Module_Bootstrap, resource loader is automatically setup.

    Notice call of initResourceLoader() method in contructor of Zend_Application_Module_Bootstrap class and code of getResourceLoader() parent method, and you'll see what I'm talking about.

  3. #3
    djcoder is offline Junior Member
    Join Date
    Apr 2009
    Posts
    10

    Default

    alokin,
    thanks for setting me on the right track.

    Here is how I solved this problem:
    1. I already had
    Code:
    resources.modules[] =
    in application/Bootstrap.php, so add it if not already present.

    2. Then, add a bootstrap to the module:
    Code:
    <?php
    class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
    {
       
    }
    And place it in application/modules/admin/Bootstrap.php

    That is it.

    This must be a change in this version of 1.10. In previous versions( ex 1.9 ) only step one above was necessary.

    Things change fast

    Thanks for the help.

+ Reply to Thread

Similar Threads

  1. Can't find class
    By limeee in forum General Q&A on Zend Framework
    Replies: 1
    Last Post: 07-06-2010, 07:24 AM
  2. Can't find model
    By Znos in forum General Q&A on Zend Framework
    Replies: 4
    Last Post: 02-17-2010, 01:39 PM
  3. Call to undefined function Zend_Application_Module_Autoloader()
    By Dr. Flink in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 11-20-2009, 07:21 AM
  4. Replies: 0
    Last Post: 05-16-2009, 10:51 AM
  5. It says it can't find the File but it's where I think it should be
    By tixrus in forum Authentication & Authorization
    Replies: 1
    Last Post: 01-15-2009, 07:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts