【问题标题】:sending data from action helper to partial view从动作助手发送数据到局部视图
【发布时间】:2012-04-12 10:18:38
【问题描述】:

我想从 Action Helper 发送一些数据来查看 Partial,但我无法做到这一点,以获得清晰的画面。这是我正在使用的所有相关代码。

在我的layout.phtml 中,我正在使用这个占位符。生成按需导航菜单。

<?php echo $this->placeholder('action-navigation'); ?>

所以当我在我的控制器或操作方法中需要它时,我可以简单地使用此代码。

$this->_helper->navigation()->renderActionNavigation();

我使用的动作助手是。

class Zend_Controller_Action_Helper_Navigation extends Zend_Controller_Action_Helper_Abstract
{
    private $_view = null;

    public function direct()
    {
        $this->_view = $view = Zend_Layout::getMvcInstance()->getView();
        $this->_view->placeholder('action-navigation');
        return $this;
    }

    public function renderActionNavigation()
    {   
        $config = new Zend_Config_Xml(
            APPLICATION_PATH.'/configs/navigation.xml', strtolower(
                $this->getRequest()->getControllerName().
                $this->getRequest()->getActionName()
            )
        );
        $container = new Zend_Navigation($config);

        // here i want to send $container to _action-navigation.phtml.

        $this->_view->addScriptPath(APPLICATION_PATH.'/layouts/')->render('partials/_action-navigation.phtml');
    }
}

这是我的部分观点_action-navigation.phtml

$this->placeholder('action-navigation')->captureStart();

//i want to get zend_navigation instance. from the above action helper here.

$this->placeholder('action-navigation')->captureEnd();

我在将数据从动作助手发送到部分视图_action-navigation.phtml 时遇到问题,我该怎么做?

谢谢。

【问题讨论】:

    标签: php zend-framework helpers zend-view


    【解决方案1】:

    使用partial() 代替render()

    $this->_view->partial('partials/_action-navigation.phtml', array('nav' => $container));
    

    在你的部分:

    $this->nav // to get your container
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 1970-01-01
      相关资源
      最近更新 更多