【问题标题】:getView() returns NULL in zend framework 2 Custom Form View HelpergetView() 在 zend 框架 2 自定义表单视图助手中返回 NULL
【发布时间】:2013-05-13 11:23:53
【问题描述】:

试图从视图助手中获取视图对象,以便我可以渲染某个部分。但我得到的只是 NULL 这是代码 命名空间 App\Form\View\Helper;

use Zend\Form\View\Helper\AbstractHelper;
use Zend\Form\View\Helper\FormInput;
use Zend\Form\ElementInterface;
class FormDate2 extends AbstractHelper
{
    protected $script = 'element-decorators/date-picker';

    public function render(ElementInterface $element, $formType = null, array $displayOptions = array())
    {
        echo '<pre>';var_dump($this->getView());echo '</pre>';die();
    }
}

【问题讨论】:

  • 您如何测试帮助程序以确定视图对象为空?
  • 使用该助手的自定义元素
  • 流程如下,一个FormRow Helper渲染元素视图部分,通过上面贴的元素的helper获取元素html

标签: zend-framework2 zend-view view-helpers


【解决方案1】:

找到了解决办法,不知道是不是最好的,如果有人有更好的请在上面发帖

在这里,从 Di 中检索视图渲染器

    public function __construct()
    {
        if($this->getView() == NULL){
            $di = new Di();
            $view = $di->get('Zend\View\Renderer\PhpRenderer');
            $this->setView($view);
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 2012-12-21
    相关资源
    最近更新 更多