Zend_View作为资源,放入Zend_Registry
我想将 Zend_View 放入 Zend_Registry 中,但我在完成这个简单的任务时遇到了麻烦。 Zend_View 在 application.ini 中作为资源初始化:
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"
它工作正常,然后我想通过在 Bootstrap.php 中添加方法将其放入注册表中。
protected function _initView()
{
$view = $this->getResource('view');
Zend_Registry::set('view', $view);
return $view;
}
刷新后,我在视图初始化中遇到错误:
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
我做错了什么?我之前没有收到 jQuery 错误
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种不同的方法来初始化资源:在 application.ini 文件中以及使用引导类中的 _init 方法。当应用程序引导时,首先运行 _init 方法,然后运行 ini 文件资源。所以你的代码的问题是,当
$this->getResource('view')
运行时,视图资源还不存在,所以这将返回 null。然后,您将该空值放入注册表中,这可能是稍后出现错误的原因。目前还不太清楚为什么需要注册表中的视图对象,所以如果您能解释一下,我们也许可以建议更好的方法。
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.
将您的 _init 方法命名为其他名称...这里可能存在名称冲突。
这在命名/语义上有点难看,它可能更适合完全设置注册表实例的注册表资源。
Call your _init method something else... there's likely a name clash here.
This is a little ugly in naming / semantics, it may be better suited in a registry resource which fully sets up your registry instance.