2009年6月4日星期四

Re: [fw-mvc] Default View Helper

Actually, I think I know why.. when you call $this->test() in your view script, the view object has to know what to prepend "test" with in order to create the full class name. It can't just assume "Default_View_Helper_Test", so it uses the plugin loader to load the class based on its stack of prefixes. So, if you register the prefix and path with your view object, it should know where to find the helper.

-Hector


On Thu, Jun 4, 2009 at 3:29 PM, Hector Virgen <djvirgen@gmail.com> wrote:
That's a good point.. However, the view object uses its own plugin loader instance for loading helpers and filters. I'm not sure why it doesn't try the autoloader first.

-Hector



On Thu, Jun 4, 2009 at 3:25 PM, Jeroen Keppens <jeroen.keppens@gmail.com> wrote:
Ok. I'm confused now. Shouldn't the autoloader be doing this? (see the _initAutoload function from my default bootstrap below)

Wkr
Jeroen

On 05 Jun 2009, at 00:23, Hector Virgen wrote:

You're not passing any options to your view resource, meaning it won't know of any custom view helper paths. Update that line in the config to look like this:

resources.view.helperPath.Default_View_Helper = APPLICATION_PATH "/views/helpers"

-Hector


On Thu, Jun 4, 2009 at 3:07 PM, Jeroen Keppens <jeroen.keppens@gmail.com> wrote:
Hi all,

I have a very odd issue. I've set up an application with different modules. As read in the docs, my main Bootstrap extends Zend_Application_Bootstrap_Bootstrap while the other module bootstraps extend Zend_Application_Module_Bootstrap.

My application.ini (related to modules) looks like this:

resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/default/controllers"
resources.frontController.moduledirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultmodule = "default"
resources.frontController.throwerrors = true
resources.frontController.params.prefixDefaultModule = true
resources.view[] = 
resources.modules =

Models, View Helpers, etc... are loaded correctly in the non-default modules. In the default module, I added an _initAutoload function like below:

protected function _initAutoload()
{
    $autoloader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Default',
        'basePath'  => dirname(__FILE__),
    ));
    return $autoloader;
}

This causes my models to be loaded correctly (i.e. Default_Model_User), but my default view helpers aren't. An example:

class Default_View_Helper_Test extends Zend_View_Helper_Abstract
{
    public function test()
    {
        return "<p>DEFAULT::TEST</p>";
    }
}

When I try to use it in my view template or layout template I get:

Plugin by name 'Test' was not found in the registry; used paths:
Zend_Dojo_View_Helper_: Zend/Dojo/View/Helper/:Zend/Dojo/View/Helper/
Zend_View_Helper_: Zend/View/Helper/:/var/www/amazium/application/modules/default/views/helpers/ 

Stack trace:
#0 /mnt/hgfs/projects/Library/Zend/View/Abstract.php(1117): Zend_Loader_PluginLoader->load('Test')
#1 /mnt/hgfs/projects/Library/Zend/View/Abstract.php(568): Zend_View_Abstract->_getPlugin('helper', 'test')
#2 /mnt/hgfs/projects/Library/Zend/View/Abstract.php(335): Zend_View_Abstract->getHelper('test')
#3 [internal function]: Zend_View_Abstract->__call('test', Array)
#4 /mnt/hgfs/projects/Cms/application/modules/default/views/scripts/index/index.phtml(9): Zend_View->test()
#5 /mnt/hgfs/projects/Library/Zend/View.php(107): include('/mnt/hgfs/proje...')
#6 /mnt/hgfs/projects/Library/Zend/View/Abstract.php(832): Zend_View->_run('/mnt/hgfs/proje...')
#7 /mnt/hgfs/projects/Library/Zend/Controller/Action/Helper/ViewRenderer.php(902): Zend_View_Abstract->render('index/index.pht...')
#8 /mnt/hgfs/projects/Library/Zend/Controller/Action/Helper/ViewRenderer.php(923): Zend_Controller_Action_Helper_ViewRenderer->renderScript('index/index.pht...', NULL)
#9 /mnt/hgfs/projects/Library/Zend/Controller/Action/Helper/ViewRenderer.php(962): Zend_Controller_Action_Helper_ViewRenderer->render()
#10 /mnt/hgfs/projects/Library/Zend/Controller/Action/HelperBroker.php(276): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#11 /mnt/hgfs/projects/Library/Zend/Controller/Action.php(522): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
#12 /mnt/hgfs/projects/Library/Zend/Controller/Dispatcher/Standard.php(288): Zend_Controller_Action->dispatch('indexAction')
#13 /mnt/hgfs/projects/Library/Zend/Controller/Front.php(945): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#14 /mnt/hgfs/projects/Library/Zend/Application/Bootstrap/Bootstrap.php(77): Zend_Controller_Front->dispatch()
#15 /mnt/hgfs/projects/Library/Zend/Application.php(328): Zend_Application_Bootstrap_Bootstrap->run()
#16 /mnt/hgfs/projects/Cms/public/index.php(26): Zend_Application->run()
#17 {main} 

I noticed in the error above that my view helper path was added correctly, but for some reason the prefix it has there is Zend_View_Helper_.

So, am I doing something wrong to get my default view helpers to work? Or is this a bug?

Thanks in advance,

Jeroen Keppens





没有评论: