-- awkaiser <[email protected]> wrote
(on Thursday, 26 February 2009, 12:19 PM -0800):
> 
> This message is intended for @weierophinney, but feel free to pitch in if you
> have a solution. :) This might be an easy one for you guys!
> 
> The short story is that I'm giving Zend_Loader_Autoloader_Resource
> (incubator) a spin and have run into some unexpected behavior. It seems to
> load my classes correctly (my page will display with the expected
> information from the database) but Zend_Loader complains with some warnings:
> 
>     Warning: Zend_Loader::include_once(Projects/Model/Projects.php)
> [function.Zend-Loader-include-once]: failed to open stream: No such file or
> directory in /[...]/library/Zend/Loader.php on line 83

Zend_Loader_Autoloader was created in part to solve the very issue you
see above. Which may seem ironic, but let me explain.

Currently, if you use Zend_Loader::registerAutoload(), you're using
Zend_Loader::loadClass() as an autolader. Internally, we use include()
in order to resolve the class. However, if any errors are thrown by
loadClass() -- such as the file not being found -- those error are
reported.

This causes issues such as you're seeing here, because there may be
additional autoloaders that can intercept it -- leading to a false error
condition.

However, if we suppress the errors... then you lose a valuable debugging
tool (suppressing the errors means nothing is reported, even parse
errors in the include()).

Zend_Loader_Autoloader gives you the _option_ of suppressing those
errors. This way you can see what paths are tried, as well as any actual
issues with the class files being loaded. Once you go to production,
however, you can suppress those errors.

To suppress the errors, grab the autoloader instance, and call the
suppressNotFoundWarnings() method with a boolean true argument:

    Zend_Loader_Autoloader::getInstance()->suppressNotFoundWarnings(true);

<snip> 

> So, it seems to be attempting to include the classes from my include path.
> My assumption is that Zend_Loader_Autoloader_Resource should take care of
> everything (like taking overriding the processing of namespaces in such a
> way that the default Zend_Loader actions are never executed) and I shouldn't
> need to touch my include_path.

Correct, it shouldn't hit your include_path at all; it should do an
internal lookup and try to resolve the class to a file.

> Is there something I need to do in my bootstrap prior to using ZLAR to avoid
> that include conflict? Right now the bootstrap has nothing specific to ZLAR
> and I'm just instantiating it in my modules' index controller init()
> functions like so:

BTW, you might want to look at the "Module" variant, as it has a lot of
this stuff already setup for you:

    $loader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Projects',
        'basePath'  => dirname(__FILE__) . '/..',
    ));

>From what you're describing, it may be that the resource autoloaders are
not properly being called prior to the main autoloader instance. I'll
look into this in the next few days and see if that's the case.

> $loader = new Zend_Loader_Autoloader_Resource(array(
>       'namespace' => 'Projects',
>       'basePath'  => dirname(__FILE__) . '/..'
> ));
> 
> $loader->addResourceTypes(array(
>       'Model' => array('path' => 'models', 'namespace' => 'Model'),
>       'DbTable'  => array('path' => 'models/DbTable', 'namespace' => 
> 'DbTable')
> ));
> 
> ... where my directory structure is:
> 
> /application
>     /modules (just showing one for illustration)
>         /projects
>             /controllers
>                 IndexController.php
>             /forms
>             /models
>                 /DbTable
>                     Categories.php
>                     Features.php
>                     ProjectCategories.php
>                     ProjectFeatures.php
>                     Projects.php
>                     ProjectsSimilar.php
>                 Projects.php
>             /views
> 
> Maybe I'm violating "best practices" for ZLAR, who knows. :) Hopefully there
> is a quick fix!

-- 
Matthew Weier O'Phinney
Software Architect       | [email protected]
Zend Framework           | http://framework.zend.com/

Reply via email to