gpt4 book ai didi

zend-framework - ZF 渲染一个 Action 并在另一个 Action 中获取 html

转载 作者:行者123 更新时间:2023-12-01 02:38:42 26 4
gpt4 key购买 nike

我想用 Zend Framework 做的是从 Action X 渲染 Action Y 并获取 html:

例子:

public xAction(){
$html = some_function_that_render_action('y');
}

public yAction(){
$this->view->somedata = 'sometext';
}

其中 y View 类似于:
<h1>Y View</h1>
<p>Somedata = <?php echo $this->somedata ?></p>

我找到了 Action 助手,但我无法从 Controller 中使用它。我该如何解决?
有可能的?

最佳答案

这是做你想做的一种可能的方法。

public function xAction()
{
$this->_helper
->viewRenderer
->setRender('y'); // render y.phtml viewscript instead of x.phtml

$this->yAction();

// now yAction has been called and zend view will render y.phtml instead of x.phtml
}

public function yAction()
{
// action code here that assigns to the view.
}

而不是使用 ViewRenderer要设置要使用的 View 脚本,您也可以像我上面展示的那样调用 yAction,但是通过调用 $html = $this->view->render('controller/y.phtml'); 来获取 html。

另见 ActionStack helper .

关于zend-framework - ZF 渲染一个 Action 并在另一个 Action 中获取 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9100649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com