Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 2.29 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Zend Autoloading models issue
  2. function _initLoaderResource()
  3. {        
  4.     $resourceLoader = new Zend_Loader_Autoloader_Resource(array(                
  5.     'basePath'  => APPLICATION_PATH,//points to the "application" path where resides "models" folder
  6.     'namespace' =>''      
  7.     ));        
  8.  
  9.     $resourceLoader->addResourceType('models', 'models/');
  10.  
  11. }
  12.        
  13. 'Initial definition of a resource type must include a namespace'
  14.        
  15. protected function _initAutoloader()
  16. {
  17.     $autoloader = Zend_Loader_Autoloader::getInstance();
  18.     $autoloader->setFallbackAutoloader(true);
  19.  
  20.     return $autoloader;
  21. }
  22.        
  23. $nameSpaceToPath = array(
  24.                             'Application'   => APPLICATION_PATH,
  25.                             'Base'          => APPLICATION_PATH . '/base',
  26.                             'Store'     => APPLICATION_PATH . '/modules/Store',
  27.                             'Payment'     => APPLICATION_PATH . '/modules/Payment',
  28.                             'Admin'     => APPLICATION_PATH . '/modules/Admin'
  29.                         );
  30.  
  31.     foreach($nameSpaceToPath as $ns => $path) {
  32.         $autoLoaderResource = new Zend_Loader_Autoloader_Resource(
  33.                             array(
  34.                                 'basePath' => $path,
  35.                                 'namespace' => $ns
  36.                             )
  37.                         );
  38.         $autoLoaderResource->addResourceType('controller','controllers','Controller');
  39.         $autoLoaderResource->addResourceType('model','models','Model');
  40.         $autoLoaderResource->addResourceType('mapper','models/mappers','Model_Mapper');
  41.         $autoLoaderResource->addResourceType('service','services','Service');
  42.         // I'm using _Util_ in the name of my utility classes, I place them in 'utils' directory
  43.         $autoLoaderResource->addResourceType('util','utils','Util');
  44.         $autoLoaderResource->addResourceType('plugin','plugins','Plugin');
  45.         $autoLoaderResource->addResourceType('form','forms','Form');
  46.         // I'm using _Exception_ in the name of my module specific exception classes, I place them in 'exceptions' directory
  47.         $autoLoaderResource->addResourceType('exception','exceptions','Exception');
  48.         $autoLoader->pushAutoloader($autoLoaderResource);
  49.     }
  50.        
  51. $autoLoaderResource->addResourceType('service','services','Service');