PHPUnit + ZF:在渲染视图时“在不在对象上下文中时使用$ this”

时间:2014-04-25 11:14:30

标签: php zend-framework view phpunit

问题:运行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就行了。

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

1 个答案:

答案 0 :(得分:0)

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

/path/to/index.phtml

上面一行和文件名周围的代码行。 (config.module.php或其他)。

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

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