简体   繁体   中英

zend 2: Variable containers in view templates with Zend\Form

I'm reading a book on ZF2 "Using Zend Framework 2" and saw something that confused me.

It was an example of using Zend\\Form in a standard MVC style app where a variable is injected into a view like normal:

return new ViewModel(array(
    'form' => $form
));

But in the template it does this:

<?php
   $form = $this->form;
   $form->prepare();
?>

Why is $this->form being assigned to a local variable? I can just do $form->prepare() and it looks like it works. If I just call $form->prepare() does it not permanently modify the $form variable container? Do you have to copy it to a local variable first before calling prepare()?

thanks for reading my book. This is just for convenience. The $form->prepare() looks shorter than $this->form->prepare() . These two ways are absolutely equivelent.

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