使用Zend Framework会话填充HTML表单 [英] Populate a HTML form with Zend Framework session
问题描述
我试图用会话中保存的数据填充HTML表单。这是我迄今为止所做的,但它不起作用:
在我的控制器中:
$ sessionErrorForm = new Zend_Session_Namespace('errorForm');
$ sessionErrorForm-> prenom = $ form ['prenom'];
$ this-> _redirect('/ inscription');
在我看来,如果会话存在,我需要在值字段中显示一些内容:
< div>< input type =textname =prenomvalue =<?php if(isset($ sessionErrorForm-> prenom)):echo $ sessionErrorForm-> prenom; endif;?> title =Pr&#233; nom */>
感谢您的帮助
好的。像这里一样。您必须先实例化会话,然后才能访问它。你可以在控制器中声明它:
$ session = new Zend_Session_Namespace('errorForm');
$ this-> view-> sessionErrorForm = $ session;
然后在 或者你可以在你的视图中声明它并像下面这样使用它: 但是,如果您在前一个请求中写入会话,则必须创建一个新的你的会话,如果你没有在范围之前声明它。 I'm trying to populate a HTML form with data saved in session. This is what i've done so far but it's not working: In my controller: In my view, i need to display something in the value field if a session exists: Thanks in advance for your help Ok. Same thing like here. You always have to instantiate your Session before you can access it. You can declare it in your controller: And access it in your view with Or you can declare it in your view and use it like the following: But nevertheless if you write into your session in a previous request you always have to create a new reference to your session, if you don't declare it in the scope before. 这篇关于使用Zend Framework会话填充HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! $ this-> sessionErrorForm code $:
$ b $ $ p $ < div>< input type =textname =prenomvalue = <?php if(isset($ this-> sessionErrorForm-> prenom)):echo $ this-> sessionErrorForm-> prenom; endif;?> title =Pr&#233; nom */>
<?php $ sessionErrorForm = new Zend_Session_Namespace('errorForm'); ?>
< div>< input type =textname =prenomvalue =<?php if(isset($ sessionErrorForm-> prenom)):echo $ sessionErrorForm-> prenom; endif ;?>中title =Pr&#233; nom */>
$sessionErrorForm = new Zend_Session_Namespace('errorForm');
$sessionErrorForm->prenom = $form['prenom'];
$this->_redirect('/inscription');
<div><input type="text" name="prenom" value="<?php if (isset($sessionErrorForm->prenom)): echo $sessionErrorForm->prenom; endif;?>" title="Prénom *"/>
$session = new Zend_Session_Namespace('errorForm');
$this->view->sessionErrorForm = $session;
$this->sessionErrorForm
:<div><input type="text" name="prenom" value="<?php if (isset($this->sessionErrorForm->prenom)): echo $this->sessionErrorForm->prenom; endif;?>" title="Prénom *"/>
<?php $sessionErrorForm = new Zend_Session_Namespace('errorForm'); ?>
<div><input type="text" name="prenom" value="<?php if (isset($sessionErrorForm->prenom)): echo $sessionErrorForm->prenom; endif;?>" title="Prénom *"/>