简体   繁体   中英

how i can pass data from coutroller to view in zend famwork

I used zendframwork, this is my code in controller

      $getRows = $this->MgGeneral->select();
            foreach($getRows as $value) {
                var_dump($value);
            }

i want send $getRow to view but it's in object (array in array), so what i need pass to view true is $value that i var_dump it's show

在此处输入图片说明

So how i can pass $value to view ?

In your controller, just pass the value to:

$this->view->yourVariable = $yourValue;

In your view, you can access the value like this:

var_dump($this->yourVariable); /* you'll get $yourValue */

Bring to your code:

$getRows = $this->MgGeneral->select();
foreach($getRows as $value) {
    $this->view->value[] = $value;
};

Thanks to @Harry

by your answer now i get correct by

    $passtoview = array();
    $getRows = $this->MgGeneral->select();
    foreach($getRows as $value) {
           $passtoview[] = $value;
    };
    var_dump($passtoview);

In your controller do:

$this->view->value = $value;

and in the view you can get it by doing:

$this->value;

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