1

I have the following code:

    public function _setHelpers() {
        Zend_Controller_Action_HelperBroker::addPrefix('My_Controller_Action_Helpers');
        Zend_Controller_Action_HelperBroker::addPath ( APPLICATION_PATH . '/controllers/helpers' );
    }

With this I can add a helper wether in My/Controller/Action/Helpers/Helper.php or /application/controllers/helpers/Helper.php. That is ok, however I need to gave priority to the one in /application/, that is: if I have both helpers load the one in /application and not the one in My/Controller/...

EDITING

I was able to fix this by changing the code to this:

    public function _setHelpers() {
    $prefix = 'My_Controller_Action_Helpers';
    Zend_Controller_Action_HelperBroker::addPrefix ( $prefix );
    Zend_Controller_Action_HelperBroker::addPath ( APPLICATION_PATH . '/controllers/helpers', 'My_Controller_Action_Helper' );
    return $this;
}

As you may notice, its almost the same, with the difference that when adding the path I added also the prefix. Thanks to all for your help.

thirtydot
  • 224,678
  • 48
  • 389
  • 349
Cito
  • 1,659
  • 3
  • 22
  • 49

1 Answers1

1

Plugin paths added to the Helper Broker use Zend_Loader_PluginLoader which uses a LIFO stack for paths, so that is the last path added is the first one checked. Given your code, since you are adding the application path second, it should have priority over the files in My/Controller (both addPrefix and addPath call the same method in Zend_Loader_PluginLoader so they are effectively the same thing.

Is this not what you are finding?

drew010
  • 68,777
  • 11
  • 134
  • 162
  • Actually no, I have this two codes: `class My_Controller_Action_Helpers_Noticia extends My_Controller_Action_Helper_Abstract { protected function _direct() { echo 1; } } class My_Controller_Action_Helper_Noticia extends Busca_Controller_Action_Helpers_Noticia { protected function _direct() { echo 2; } }` The first one is My/Controller/... and the second one in Controllers/Helpers/ And it shows 1 in the view... – Cito Apr 26 '12 at 16:01
  • In that case the reason is because one of the classes isn't named correctly so it won't be loaded. Depending on your app prefix, I think you have to change the one in `Controllers/Helpers` to be called `Busca_Controller_Action_Helper_Noticia` and make sure the location is `application/controllers/action/helpers/Noticia.php` – drew010 Apr 26 '12 at 17:13
  • The thing is that it was allright, the problem was other, but I already figure it out. Thanks for your help, you give me the clue to fix it (since I printed the prefix was being added to Zend_Controller_Action_HelperBroker::getPluginLoader ()->getPaths () and in that way I saw the need of add also the prefix to addPath) Thanks a lot! – Cito Apr 26 '12 at 17:25