I'm trying to include custom view helpers in my application but keep getting
an exception thrown.

A shortened example of my code:

class TJ_View_Helper_SpecialLink
{
        public function specialLink($variables) {//relevant code here   }
}

When I try and access it from a view script, I get an exception thrown in
Zend_View_Abstract _loadClass():
helper 'specialLink' not found in path.

In my bootstrap file I do the following:
$view = new Zend_View();
$view->addHelperPath($basedir.'/app/views/helpers', 'TJ_View_Helper');

and Zend_Debug::dump($view->getHelperPaths()) in the bootstrap shows in part
this:
array(2) { [0] => array(2) {
    ["prefix"] => string(15) "TJ_View_Helper_"
    ["dir"] => string(47) "/home/username/app/views/helpers/"   }

Yet when I dump getHelperPaths in the IndexController, or dump
_path['helper'] in the view abstract _loadClass function:
array(2) {  [0] => array(2) {
    ["prefix"] => string(17) "Zend_View_Helper_"
    ["dir"] => string(21) "../app/views/helpers/"   }

This is no longer TJ, but Zend, and causes the error because _loadClass
manages to include the file, and then asks:
if (class_exists($class, false))

but $class is "Zend_View_Helper_specialLink" rather than
TJ_View_Helper_specialLink, even though it loaded the correct file.  This is
because the HelperPaths are all Zend_View_Helper prefixes rather than what I
originally added and set in the bootstrap

I can solve the error by calling my class a Zend_View_Helper, but I'd rather
not do this, and the documentation suggests I should be able to use my own
prefix (and even seems to recommend it).

Any suggestions for what I'm doing wrong?
-- 
View this message in context: 
http://www.nabble.com/Troubleshooting-view-helpers---custom-prefix-doesn%27t-stay-tf4312081s16154.html#a12276307
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to