-- J DeBord <[email protected]> wrote
(on Sunday, 03 May 2009, 09:23 PM +0200):
> On Sun, May 3, 2009 at 5:14 PM, Matthew Weier O'Phinney <[email protected]>
> wrote:
> 
>     -- J DeBord <[email protected]> wrote
>     (on Sunday, 03 May 2009, 04:49 PM +0200):
>     > Adding namespaces to the new Autoloader works great as long as they are
>     in the
>     > include path. For example, a namespace 'App_' which refers to classes in
>     the
>     > 'App' directory that sits next to the Zend (framework) directory.
>     >
>     > Question:
>     >
>     > Is there anyway to autoload the classes inside the APPLICATION_PATH . '/
>     models'
>     > directory without putting this directory on the include path? For,
>     example when
>     > you instantiate Model_Users, the autoloader knows to look for
>     APPLICATION_PATH
>     > .'/models/Users.php'
>     >
>     > I started by trying to use Application_Module_Resource_Autoloader and 
> the
>     > theory sounded right to me, however it did not work.
> 
>     The resource autoloader and/or the Zend_Application_Module_Autoloader
>     variant are definitely the answer. However, resource autoloaders expect
>     at least a component prefix (the vendor namespace can be empty); as
>     such, assuming you created an instance of
>     Zend_Application_Module_Autoloader as follows:
> 
>        $loader = new Zend_Application_Module_Autoloader(array(
>            'basePath'  => APPLICATION_PATH,
>            'namespace' => '', // no resource namespace
>        ));
> 
>     your models would then be prefixed with 'Model_'.
> 
> 
> Ahhhhhh, excellent. This is great. Once you get your head around it, this 
> makes
> so much more sense and is so much easier than "the old way." Great work 
> Matthew
> et al. Absolutely great!
> 
> I quickly rewrote some code and it works perfectly with
> Zend_App.._Mod.._Autoloader. I can use the resource autoloader to do the same
> thing? Sounds better sense I'm not dealing with any specific module.

Zend_Loader_Autoloader_Resource provides the ability to map components
to directories under a common (optional) namespace and base path.
Zend_Application_Module_Autoloader simply defines some specific mappings
based on our recommended directory structure. If you're using your own
directory structure, extend Zend_Loader_Autoloader_Resource to define
your mappings, and use an instance of it in your application.


>     > On Sun, May 3, 2009 at 2:25 PM, Matthew Weier O'Phinney 
> <[email protected]
>     >
>     > wrote:
>     >
>     >     -- J DeBord <[email protected]> wrote
>     >     (on Saturday, 02 May 2009, 07:43 PM +0200):
>     >     > My code:
>     >     >
>     >     > require_once 'Zend/Loader/Autoloader.php';
>     >     > $autoloader = Zend_Loader_Autoloader::getInstance();
>     >     > $autoloader->registerNamespace(array('Amazon_', 'Nba_'));
>     >     >
>     >     > $filesDomain = new Nba_SimpleDb_Domain_Files;
>     >     >
>     >     > There is a parse error in the class Nba_SimpleDb_Domain_Files.
>     >     > With the code above, when executed, the screen is blank.
>     >
>     >     This slipped under my radar: suppression is on by default.
>     >
>     >     Call this when you're doing your autoloader setup:
>     >
>     >        $autoloader->suppressNotFoundWarnings(false);
>     >
>     >     and you should start seeing parse errors.
>     >
>     >     > If I add:
>     >     >
>     >     > require_once('Nba/SimpleDb/Domain/Files.php');
>     >     >
>     >     > I get the parse error.
>     >     >
>     >     > My error reporting fwiw:
>     >     >
>     >     > error_reporting(E_ALL|E_STRICT);
>     >     > ini_set('display_errors', 'on');
>     >     > ini_set('display_startup_errors', 'on');
>     >     >
>     >     > Any hints?
>     >     >
>     >     >
>     >     > On Sat, May 2, 2009 at 6:20 PM, J DeBord <[email protected]>
>     wrote:
>     >     >
>     >     >     Alright, I read the article. Great as usual. Thanks Matthew.
>     >     >
>     >     >     The following paragraph caught my attention early on:
>     >     >
>     >     >     "So, we then tried using the suppression operator ('@'). This
>     gets
>     >     rid of
>     >     >     the error notices (though they still show up in logs) -- but
>     has a
>     >     really
>     >     >     nasty side effect: if there are parse or compilation errors
>     when
>     >     attempting
>     >     >     to load the class, nothing is reported, and you end up with a
>     blank
>     >     white
>     >     >     screen with no information."
>     >     >
>     >     >     Since changing to the Zend_Loader_Autooader, I've been 
> noticing
>     this
>     >     exact
>     >     >     thing is happening. I'll do some investigating, but as of 
> right
>     now,
>     >     if I
>     >     >     accidentally use = in an associative array as opposed to => 
> for
>     >     example, I
>     >     >     get the blank white screen instead of a parse error.
>     >     >
>     >     >     Article was great. I'm going to keep plugging away. Thanks!
>     >     >
>     >     >
>     >     >
>     >     >     On Sat, May 2, 2009 at 6:02 PM, J DeBord <[email protected]>
>     wrote:
>     >     >
>     >     >         Thanks guys! I will be reading Matthew's Dev Zone article
>     this
>     >     evening.
>     >     >
>     >     >         Regarding registerNamespace(). How exactly does this work?
>     What
>     >     is the
>     >     >         advantage? For example I'm using an Amazon SimpleDb
>     library. I
>     >     keep it
>     >     >         in the same library directory next to my Zend (framework)
>     >     directory.
>     >     >         The library directory is on the include path. All the 
> class
>     names
>     >     in
>     >     >         the Amazon directory begin with Amazon_ and use the same
>     naming
>     >     >         conventions as the Zend Framework. Should I
>     registerNamespace
>     >     >         ('Amazon_') and forego using the setFallbackAutoloader
>     (true) ?
>     >     >
>     >     >         Thanks again!
>     >     >
>     >     >         J
>     >     >
>     >     >
>     >     >
>     >     >         On Sat, May 2, 2009 at 4:30 PM, Matthew Weier O'Phinney <
>     >     >         [email protected]> wrote:
>     >     >
>     >     >             -- David Mintz <[email protected]> wrote
>     >     >             (on Saturday, 02 May 2009, 08:54 AM -0400):
>     >     >             > On Sat, May 2, 2009 at 8:50 AM, Matthew Weier
>     O'Phinney <
>     >     >             [email protected]>
>     >     >             > wrote:
>     >     >             >     -- J DeBord <[email protected]> wrote
>     >     >             >     (on Saturday, 02 May 2009, 11:32 AM +0200):
>     >     >             >     > To make Zend_Loader_Autoloader match the
>     >     functionality of
>     >     >             this:
>     >     >             >     >
>     >     >             >     > require_once "Zend/Loader.php";
>     >     >             >     > Zend_Loader::registerAutoload();
>     >     >             >     >
>     >     >             >     > Would you do this? :
>     >     >             >     >
>     >     >             >     > require_once 'Zend/Loader/Autoloader.php';
>     >     >             >     > $autoloader =
>     Zend_Loader_Autoloader::getInstance();
>     >     >             >     > $autoloader->setFallbackAutoloader(true);
>     >     >             >
>     >     >             >     Yes, though the last line can be omitted if
>     you're not
>     >     using
>     >     >             any
>     >     >             >     libraries outside of Zend_ or ZendX_ trees. Or,
>     if you
>     >     know
>     >     >             the exact
>     >     >             >     namespaces of any other libraries, register 
> them:
>     >     >             >
>     >     >             >        $autoloader->registerNamespace(array('Foo_',
>     >     'Bar_'));
>     >     >             >
>     >     >             > If we could stick a sticky on this little thread...!
>     I can
>     >     >             promise this will
>     >     >             > get asked a lot as people's apps blow up following
>     upgrade
>     >     to 1.8
>     >     >
>     >     >             I'll add it to the FAQ and release notes.
>     >     >
>     >     >             The article I wrote for devzone yesterday appears to 
> be
>     >     helping the
>     >     >             transition for many, however.
>     >     >
>     >     >             --
>     >     >             Matthew Weier O'Phinney
>     >     >             Project Lead            | [email protected]
>     >     >             Zend Framework          | http://framework.zend.com/
>     >     >
>     >     >
>     >     >
>     >     >
>     >     >
>     >     >
>     >
>     >     --
>     >     Matthew Weier O'Phinney
>     >     Project Lead            | [email protected]
>     >     Zend Framework          | http://framework.zend.com/
>     >
>     >
> 
>     --
>     Matthew Weier O'Phinney
>     Project Lead            | [email protected]
>     Zend Framework          | http://framework.zend.com/
> 
> 

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

Reply via email to