-- majelbstoat <[EMAIL PROTECTED]> wrote
(on Sunday, 09 March 2008, 06:28 AM -0700):
> Quick question about view helpers - couldn't find the answer having
> searched, so here goes.  I'm using the standard module based directory tree. 
> However, I have a number of view helpers that are shared between the
> modules, so it doesn't make sense to put them in module/xxx/view/helpers.
> 
> Where can I put them, and what steps do I need to take so that they
> *autoload* when I call $this->myHelper() from index.phtml?
> 
> I tried the following so far:
> 1.  I put all my helpers in /lib/My/View/Helper/ , with appropriate
> classnames.
> 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.

> so that all the controllers have access to them.
> 3.  the /lib/ directory is already in my include path, so that classes can
> be autoloaded.
> 
> There are no problems finding the right file in the path.  However, the
> class isn't loaded from the file, because
> Zend_View_Controller_Abstract::loadClass() calls class_exists($class,
> false).  If it called class_exists($class, true), there wouldn't be an
> issue.  (Why don't we want to autoload here, by the way?)
> 
> I'd like to avoid centralised loading of helpers because some of them will
> be redundant on most pages.  I'd also like to avoid writing include_once or
> Zend_Loader all over the place for maintenance and tidiness reasons.
> 
> Any help greatly appreciated,

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

Reply via email to