Zend 框架如何在使用 render() 时从视图和控制器中获取值?
Zend framework how can i get value from view and controller when render() is used?
我在 layout/formsde/url.phtml
中有此代码:
<?php
$use_url = $this->use_url;
foreach($this->match_de as $k=>$v) {
if($this->serverUrl(true) == $k) {
$use_url = $v;
}
}
?>
我有 1000 页,其中包含以下行:
<?=$this->render("layout/formsde/url");?>
现在的问题是 $this->use_url
并且 $this->match_de
为空,它没有从如下分配的控制器中获取值:
return new ViewModel(array(
'description' => $this->de_desc,
'use_url' => $this->layout()->use_url,
'match_de' => $this->layout()->match_de,
));
如何将值传递给 ->render() ?这样我就有了 $this->match_de
控制器中的确切值?
您可以将包含您需要的值的数组传递给渲染器
//Example
$this->render('layout/formsde/url', array(
'use_url' => $this->use_url,
'match_de' => $this->match_de));
可以在视图渲染器渲染的模板中定义变量Zend\View\Renderer\PhpRenderer
。您可以将第二个参数作为数组传递。
<?=$this->render("layout/formsde/url", array(
'description' => $this->de_desc,
'use_url' => $this->layout()->use_url,
'match_de' => $this->layout()->match_de,
));?>
有关 PhpRenderer::render() 方法的更多信息,请参见 here。
我在 layout/formsde/url.phtml
中有此代码:
<?php
$use_url = $this->use_url;
foreach($this->match_de as $k=>$v) {
if($this->serverUrl(true) == $k) {
$use_url = $v;
}
}
?>
我有 1000 页,其中包含以下行:
<?=$this->render("layout/formsde/url");?>
现在的问题是 $this->use_url
并且 $this->match_de
为空,它没有从如下分配的控制器中获取值:
return new ViewModel(array(
'description' => $this->de_desc,
'use_url' => $this->layout()->use_url,
'match_de' => $this->layout()->match_de,
));
如何将值传递给 ->render() ?这样我就有了 $this->match_de
控制器中的确切值?
您可以将包含您需要的值的数组传递给渲染器
//Example
$this->render('layout/formsde/url', array(
'use_url' => $this->use_url,
'match_de' => $this->match_de));
可以在视图渲染器渲染的模板中定义变量Zend\View\Renderer\PhpRenderer
。您可以将第二个参数作为数组传递。
<?=$this->render("layout/formsde/url", array(
'description' => $this->de_desc,
'use_url' => $this->layout()->use_url,
'match_de' => $this->layout()->match_de,
));?>
有关 PhpRenderer::render() 方法的更多信息,请参见 here。