简体   繁体   English

Zend框架使用render()时如何从视图和控制器中获取价值?

[英]Zend framework how can i get value from view and controller when render() is used?

I have this code in layout/formsde/url.phtml : 我在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;  
  }
}
?>

I have 1000 pages with following line: 我有以下页面的1000页:

<?=$this->render("layout/formsde/url");?>

Now the problem is $this->use_url and $this->match_de is null its not getting the value from Controllers where it is assigned as below: 现在问题是$this->use_url$this->match_de为null,它没有从分配如下的Controllers获取值:

return new ViewModel(array(
    'description' => $this->de_desc,
    'use_url' => $this->layout()->use_url,
    'match_de' => $this->layout()->match_de,          
));

How can i pass the value to ->render() ? 如何将值传递给-> render()? so that i have $this->match_de value with exact which is in controller? 这样我有$this->match_de值与确切在控制器中?

You can pass array with values you need to the render 您可以将具有所需值的数组传递给渲染

//Example
$this->render('layout/formsde/url', array(
       'use_url' => $this->use_url, 
       'match_de' => $this->match_de)); 

Its possible to define variables in the template which is rendered by the view renderer Zend\\View\\Renderer\\PhpRenderer . 可以在由视图渲染器Zend\\View\\Renderer\\PhpRenderer渲染的模板中定义变量。 You can pass an second argument as array. 您可以将第二个参数作为数组传递。

<?=$this->render("layout/formsde/url", array(
    'description' => $this->de_desc,
    'use_url' => $this->layout()->use_url,
    'match_de' => $this->layout()->match_de,          
));?>

More information about PhpRenderer::render() method can be found in the here . 有关PhpRenderer :: render()方法的更多信息,请参见here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Zend Framework中将值从视图传递到控制器? - How can I pass a value from view to controller in Zend Framework? 我可以渲染视图而不在zend Framework 2的动作控制器中返回它吗? - Can I render view without returning it in action controller in zend framework 2? zend框架从控制器获取一个变量来查看 - zend framework get a variable from the controller to view 如何从控制器访问Zend Framework应用程序的配置? - How can I access the configuration of a Zend Framework application from a controller? 如何从视图的 URL 获取值并在控制器中使用它? - How can I get a value from the URL of a view and use it in controller? 如何在不使用Zend Framework 2中的锚标记和表单的情况下将值从视图传递到控制器 - How to pass value from view to controller without using anchor tag and forms in Zend Framework 2 如何在Zend Framework中的视图上获取控制器名称和动作名称? - How to get controller name and action name on view in Zend Framework? 如何在Zend Framework 2中使用插件呈现自定义视图 - How to Render a custom view with plugins in Zend Framework 2 如何使用zend Framework 3在变量中呈现模板? - how can i render template in a variable with zend framework 3? Zend Framework在模块/控制器中渲染不同的视图 - Zend Framework Render different view within module/controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM