2008年12月17日星期三

Re: [fw-mvc] Action Controllers extending custom one and include path in version 1.7.1

-- iosonogio <iosonogio99@yahoo.com> wrote
(on Wednesday, 17 December 2008, 12:40 PM -0800):
> > ZF does not manipulate the include_path.
>
> Actually it does.
> Zend_Loader calls set_include_path() in the loadFile() function.

What I meant is that it doesn't arbitrarily set the include_path to
include the ZF directories. If you look at the usage in there, it's used
when directories are passed to the second argument of the loadFile()
method so that the specified set of directories is searched. It then
resets it back to the original state.

> > Autoloading of controllers has never been supported, and we use
> > Zend_Loader::loadClass() within the dispatcher, passing it a directory
> > in which to look for the class file,
>
> Correct, but loadClass() in turn calls loadFile() which calls
> set_include_path() which sets the new path by adding the controllers
> directories to it as I configured them when creating the front controller!
>
> (actually I dont even need to configure the controllers directories if I use
> a standard layout e.g. application/modules/default/controllers)

I stand by what I said earlier: the dispatcher is _not_ responsible for
loading your base class, and as the base controller is not on your
include_path, you will either need to (a) put it on your include_path,
or (b) use a require_once statement in your controller class definitions
that resolves to the base controller class file appropriately.

> > This mechanism would never be used to find a custom base
> > controller class, as that class would never be loaded by the dispatcher.
> > ZF is not at fault here; something has changed in your environment or
> > code.
>
> I just switch the Zend library directory from the 1.7.1 to the 1.6.2 to make
> it work, and switch it back to 1.7.1 to make it stop working.
> I do not change anything else in my environment.
>
> With 1.7.1 it does require my base action controller class to be in
> the include path. With 1.6.2 it does not.
>
> Just try yourself :-)

First off, I typically do not use base controllers -- it's better to
utilize action helpers for shared functionality. Second, when I *do* use
base controllers, I always do one of the two options I specified
earlier.

If things worked for you before, then it was a fluke, and you were
relying on unstable functionality.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: