开发者

Zend_View as resource, put into Zend_Registry

I want to put Zend_View into Zend_Registry and I am having trouble with that simple task. Zend_View is initialized in application.ini as resource:

resources.view.encoding = "UTF-8"
resources.view.contentType = "text/html; charset=UTF-8"
resources.view.doctype = "HTML4_STRICT"
resources.view.helperPath.ZendX_JQuery_View_Helper = "ZendX/JQuery/View/Helper"

It works fine, then I wanted to put this in registry by adding method in Bootstrap.php.

protected function _initView()
{
    $view = $this->getResource('view');
    Zend_Registry::set('view', $view);

    return $view;
}

And after refresh I get errors in View initialization:

Catchable fatal error: Argument 1 passed to ZendX_JQuery::enableView() must be an instance of Zend_View_Interface, null given, called in D:\projekty\xxx\library\ZendX\Application\Resource\Jquery.php on line 91 and defined开发者_运维问答 in D:\projekty\xxx\library\ZendX\JQuery.php on line 104

What am I doing wrong? I don't get that jQuery error before


There are two different ways to initialise a resource: in the application.ini file and using an _init method in the bootstrap class. When the application is bootstrapped, the _init methods run first, followed by the ini file resources. So the problem with your code is that when $this->getResource('view') runs, the view resource doesn't exist yet, so this will return null. You're then putting that null in the registry, which presumably is the cause of the error later on.

It's not quite clear why you need the view object in the registry, so perhaps if you could explain that we might be able to suggest a better approach.


Call your _init method something else... there's likely a name clash here.

protected function _initViewInRegistry() {
    // run view resource
    $this->bootstrap('view');

    // put view resource in registry
    Zend_Registry::set('view', $this->getResource('view'));
}

This is a little ugly in naming / semantics, it may be better suited in a registry resource which fully sets up your registry instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜