-- majelbstoat <[EMAIL PROTECTED]> wrote
(on Sunday, 09 March 2008, 05:08 PM -0700):
> Matthew Weier O'Phinney-3 wrote:
> > 
> >> 2.  In a common parent controller class, I add:
> >> 
> >>            $this->view->addHelperPath(Zend_Registry::get('applicationDir') 
> >> .
> >> '/lib',
> >> 'My_View_Helper');
> > 
> > You need the full path to the helpers:
> >     
> >     Zend_Registry::get('applicationDir') . '/lib/My/View/Helper'
> > 
> > otherwise, it would be looking for them in just your lib dir, and would
> > not find them.
> 
> As easy as that hey? :) Is there any mileage in a slight alteration to
> loadClass that would look like this:
> 
>               $path = str_replace('_', '/', $prefix);
>               if (Zend_Loader::isReadable($dir . $file)) {
>                   include_once $dir . $file;
>               } elseif (Zend_Loader::isReadable($dir . $path . $file)) {
>                   include_once $dir . $path . $file;
>               }
> 
> instead of what is there currently:
> 
>               if (Zend_Loader::isReadable($dir . $file)) {
>                   include_once $dir . $file;
>               }
> 
> Redundant perhaps, in light of your reply, but potentially still useful for
> consistency?  I got confused and assumed that the prefixing the classes
> would trigger path parsing as it does in other areas of the framework...

Helpers compare the helper name called and look at it as the *last*
segment of a class name, and then apply a prefix to it. Internally, in
Zend_View as well as Zend_Loader_PluginLoader, we match a prefix to a
path -- and the assumption is that all classes in that path have that
prefix.

What you're suggesting is more along the lines of an include_path style
directive -- and this gets much harder to match as well as much less
performant.

In the future, we will likely incorporate Zend_Loader_PluginLoader into
Zend_View, which will make it more consistent with the other components
containing helpers of plugins (we'll likely do the same with
Zend_Controller_Action_HelperBroker and Zend_Controller_Plugin_Broker)
which will allow you to create alternate PluginLoader implementations
and attach them to Zend_View. This means that if the above functionality
is how *you* would like to work with helpers, you'll be able to do so by
writing your own PluginLoader.

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to