Render a view in Zend ?

本文探讨了在Zend框架中两种不同的视图渲染方法:使用Zend_Controller_Action_Helper_ViewRenderer辅助函数与通过Zend_Controller_Action中的render()方法直接进行渲染。文章详细对比了这两种方式的实现逻辑,并解释了它们之间的差异。
摘要由CSDN通过智能技术生成
There are two ways to render the view. One is to use action render helper:Zend_Controller_Action_Helper_ViewRenderer, The other way is to use render() method in the Zend_Controller_Action.
You may be curious of the difference between these two approaches. In my eyes, Zend_Controller_Action_Helper_ViewRenderer provides us a more helpful way to render the view.

1.The logic in the Zend_Controller_Action's rende() method

    public function render($action = null, $name = null, $noController = false)
    {
        if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
            return $this->_helper->viewRenderer->render($action, $name, $noController);
        }

        $view   = $this->initView();
        $script = $this->getViewScript($action, $noController);

        $this->getResponse()->appendBody(
            $view->render($script),
            $name
        );
    }

2.The magic power in Zend_Controller_Action_Helper_ViewRenderer

    public function postDispatch()
    {
        if ($this->_shouldRender()) {
            $this->render();
        }
    }
    public function render($action = null, $name = null, $noController = null)
    {
        $this->setRender($action, $name, $noController);
        $path = $this->getViewScript();
        $this->renderScript($path, $name);
    }
    public function renderScript($script, $name = null)
    {
        if (null === $name) {
            $name = $this->getResponseSegment();
        }

        $this->getResponse()->appendBody(
            $this->view->render($script),
            $name
        );

        $this->setNoRender();
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值