【问题标题】:PHPUnit + ZF : "Using $this when not in object context" while rendering viewPHPUnit + ZF:渲染视图时“不在对象上下文中使用$this”
【发布时间】:2014-06-11 01:40:39
【问题描述】:

问题:运行 phpunit 导致下一个错误:

PHPUnit_Framework_Exception: PHP Fatal error:  Using $this when not in object context in /path/to/index.phtml

回溯:

#0  include() called at [/path/to/Zend/View.php:108]
#1  Zend_View->_run(/path/to/index.phtml) called at [/path/to/Zend/View/Abstract.php:880]
#2  Zend_View_Abstract->render(index/index.phtml) called at [/path/to/Zend/Controller/Action/Helper/ViewRenderer.php:897]
#3  Zend_Controller_Action_Helper_ViewRenderer->renderScript(index/index.phtml, ) called at [/path/to/Zend/Controller/Action/Helper/ViewRenderer.php:918]
#4  Zend_Controller_Action_Helper_ViewRenderer->render() called at [/path/to/Zend/Controller/Action/Helper/ViewRenderer.php:957]
#5  Zend_Controller_Action_Helper_ViewRenderer->postDispatch() called at [/path/to/Zend/Controller/Action/HelperBroker.php:277]
#6  Zend_Controller_Action_HelperBroker->notifyPostDispatch() called at [/path/to/Zend/Controller/Action.php:523]
#7  Zend_Controller_Action->dispatch(indexAction) called at [/path/to/Zend/Controller/Dispatcher/Standard.php:295]

无法理解我缺少什么,但正如我所见,include 是从 Zend_View->run 调用的,因此 $this 必须在视图中可见(并且它在没有 phpunit 的情况下也可以工作)。

你能告诉我挖掘的方向或这种行为的一些原因吗?

【问题讨论】:

    标签: php zend-framework view phpunit


    【解决方案1】:

    您能否与我们分享您必须编写的一段代码-

    /path/to/index.phtml
    

    只有上一行和文件名周围的代码行。 (config.module.php 什么的)。

    可能是上面这行代码(/path/to/)需要替换成实际路径。

    如果可能的话,您能否分享一下您用于 PHPUnit + ZF 实现的教程或博客。

    【讨论】:

    • 关于代码:如果您使用的是 ZF,您知道调用/index/ 将上升Zend_View->run(/application/views/scripts/index/index.phtml)(或您设置的任何其他扩展名)。所以我不明白你需要什么代码。关于 PHPUnit + ZF:我只使用官方的 PHPUnit 文档和自己的 ZF 知识(大约使用 3 年)。不幸的是,内置的 Zend_Test_PHPUnit 已经过时了。
    猜你喜欢
    • 1970-01-01
    • 2014-06-20
    • 2017-09-21
    • 2015-02-12
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多