2010年12月8日星期三

Re: [fw-mvc] Application autoloading

-- K.L. <coviex@gmail.com> wrote
(on Wednesday, 08 December 2010, 06:28 PM +0200):
> I thought both are about autoloading.

appnamespace is only tangentially about autoloading. More below.

> And sorry, but it's still not clear what "appnamespace" is for.
> Lets imaging I've created project with Zend_Tool.
> And then changed config to "appnamespace = "Zoo"" instead of
> "appnamespace = "Application"".
> What should I do now for the project to work like if it still was
> "appnamespace = "Application""?

Let's look at a common directory structure:

application/
configs/
controllers/
forms/
models/
views/
helpers/
scripts/
library/
Application/
...

The following configuration setting:

autoloaderNamespaces[] = "Application"

is telling the autoloader that if it finds a class prefix of
"Application", it should try and load it. Zend_Loader_Autoloader only
looks on the include_path -- which will include your library/ folder,
but not the application/ folder. So, it will see if a matching classfile
exists under library/Application/.

Now, the other configuration setting:

appnamespace = "Application"

is telling Zend_Application that classes under the default module are
using the prefix "Application". Looking again at our structure, we'd see
the following mappings::

application/
Bootstrap.php -> Application_Bootstrap
forms/
Login.php -> Application_Form_Login
models/
User.php -> Application_Model_User
views/
helpers/
LoginForm.php -> Application_View_Helper_LoginForm

If you change the setting to read:

appnamespace = "Zoo"

you need to update all classes under application/ to use the "Zoo"
prefix.


> On Wed, Dec 8, 2010 at 5:37 PM, Matthew Weier O'Phinney
> <matthew@zend.com> wrote:
> > -- K.L. <coviex@gmail.com> wrote
> > (on Wednesday, 08 December 2010, 05:03 PM +0200):
> >> I instantiate Zend_Application with this part of config:
> >>
> >> autoloaderNamespaces[] = "Application"
> >> autoloaderNamespaces[] = "Other"
> >> appnamespace               = "Application"
> >>
> >> Question is why should I write "autoloaderNamespaces[] =
> >> "Application"" if then I have this "appnamespace = "Application""?
> >> Looks like overlapping.
> >
> > They're not.
> >
> > The first directive (autoloaderNamespaces) is adding an additional
> > namespace that the Autoloader will attempt to respond for.
> >
> > The second directive (appnamespace) is telling Zend_Application the
> > prefix used for the application bootstrap (and default module).
> >
> > The two are quite separate -- the first is intended typically for code
> > in your _library_, not within the application; you will usually use a
> > resource autoloader within your application code for loading assets
> > (forms, view helpers, models, etc.).
> >
> >> "appnamespace = "Application"" helps load all classes with prefix
> >> "Application_Aplication" which are in Zend sibling directory
> >> "Application".
> >
> > Wrong. See above.
> >
> >> But it doesn't help classes which are right there in "Application"
> >> directory, say, with "Application_Form" prefix.
> >> Why is it so? Or I miss something?
> >
> > If your bootstrap extends Zend_Application_Bootstrap or
> > Zend_Application_Module_Bootstrap, a resource autoloader using the
> > appnamespace directive *should* be loaded for you, giving access to
> > those resources. If this is not the case, you'll need to provide better
> > detail of your application file structure, and some samples of class
> > names found in some of the files -- that information will help us
> > troubleshoot better.
> >
> > --
> > Matthew Weier O'Phinney
> > Project Lead            | matthew@zend.com
> > Zend Framework          | http://framework.zend.com/
> > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
> >
>
>
>
> --
> Opera.com
>

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

没有评论: