2009年2月28日星期六

Re: [fw-mvc] Proper use of Zend_Loader_Autoloader_Resource

Hi,

May sound stupid but now i got same error. I din't changed anything back, just developed further.

So, error is it:

Warning: include(D:\_Work\site/application/modules/models//Plugins.php) [function.include]: failed to open stream: No such file or directory in D:\_Work\site\library\incubator\Zend\Loader\Autoloader\Resource.php on line 173

Warning: include(D:\_Work\site/application/modules/models//Plugins.php) [function.include]: failed to open stream: No such file or directory in D:\_Work\site\library\incubator\Zend\Loader\Autoloader\Resource.php on line 173

Warning: include() [function.include]: Failed opening 'D:\_Work\site/application/modules/models//Plugins.php' for inclusion (include_path='D:\_Work\site/library/dasprid;D:\_Work\site/library/incubator;D:\_Work\site/library;.;C:\php5\pear') in D:\_Work\site\library\incubator\Zend\Loader\Autoloader\Resource.php on line 173

Fatal error: Class 'Default_Model_Plugins' not found in D:\_Work\site\application\Bootstrap.php on line 29

//index.php

<?php
    if( !defined('APPLICATION_ENVIRONMENT'))
        define('APPLICATION_ENVIRONMENT', 'production');
       
    define('PUBLIC_PATH', realpath(dirname(__FILE__)));
    define('BASE_PATH', realpath(dirname(dirname(__FILE__))));
    define('APPLICATION_PATH', BASE_PATH . '/application');
    define('MODULE_PATH', APPLICATION_PATH . '/modules');
   
    set_include_path(
        BASE_PATH . '/library/dasprid' . PATH_SEPARATOR
        .BASE_PATH . '/library/incubator' . PATH_SEPARATOR
        .BASE_PATH . '/library' . PATH_SEPARATOR
        . get_include_path()
    );
   
    require_once APPLICATION_PATH.'/Bootstrap.php';
   
    $boot = new Bootstrap();
    $boot->run();
?>

//bootstrap
// no use ofZend_Loader::registerAutoload();

         require 'Zend/Loader/Autoloader.php';
        require 'Zend/Loader/Autoloader/Resource.php';
       
        Zend_Loader_Autoloader::getInstance()->registerNamespace('Imagis');
       
        $loader = new Zend_Loader_Autoloader_Resource(array(
             'namespace' => 'Default_',
             'basePath'  => MODULE_PATH
        ));
       
        $loader->addResourceType('Model', 'models', 'Model');
        $plugins = new Default_Model_Plugins();
       ................................................

I can't think to any change on bootstrap or index to led me to same error again... Which error was trapped by Zend_Loader::registerAutoload(), now gone.

I am using now latest from SVN.

--  Best regards, Cristian Bichis www.zftutorials.com | www.zfforums.com | www.zftalk.com | www.zflinks.com

-- Cristian Bichis <contact@zftutorials.com> wrote (on Friday, 27 February 2009, 10:24 AM +0200):   
I tried last days to get in touch with some newer (or TBA) features of ZF. One of them is Zend_Loader_Autoloader_Resource.  I made a sample for a modular archtecture. I am trying as a demonstration to load a Plugins model from /application/modules/default/models  That's into application/Bootstrap.php:          Zend_Loader::registerAutoload();                 $autoloader = new Zend_Loader_Autoloader_Resource(             array(             'namespace'   => 'Default',             'basePath' => MODULE_PATH             )         );                 $autoloader->addResourceTypes(array(                 'Model' => array('path' => 'models', 'namespace' => 'Model'),                 'DbTable'  => array('path' => 'models/DbTable', 'namespace' => 'DbTable')         ));     
 Okay, two things here. First, if you're going to use the Resource autoloader, don't uses Zend_Loader::registerAutoload(); use Zend_Loader_Autoloader -- and the latter is implicit when you instantiate the resource autoloader.  Second, based on the resource types you're defining, you probably want to use the Zend_Application_Module_Autoloader variant, as it has all of the resources you indicated above defined already.  In the end, it would look like this:      $autoloader = new Zend_Application_Module_Autoloader(array(         'namespace' => 'Default_',         'basePath'  => MODULE_PATH,     ));  and that's it.

没有评论: