简体   繁体   中英

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

I have this code in 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:

<?=$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:

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() ? so that i have $this->match_de value with exact which is in controller?

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 . 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM