使用Zend Framework会话填充HTML表单 [英] Populate a HTML form with Zend Framework session

查看:131
本文介绍了使用Zend Framework会话填充HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用会话中保存的数据填充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;

然后在 $ 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 */>

但是,如果您在前一个请求中写入会话,则必须创建一个新的你的会话,如果你没有在范围之前声明它。


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:

      $sessionErrorForm = new Zend_Session_Namespace('errorForm');

      $sessionErrorForm->prenom     = $form['prenom'];

      $this->_redirect('/inscription');

In my view, i need to display something in the value field if a session exists:

 <div><input type="text" name="prenom" value="<?php if (isset($sessionErrorForm->prenom)): echo $sessionErrorForm->prenom; endif;?>" title="Pr&#233;nom *"/>

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:

$session = new Zend_Session_Namespace('errorForm');
$this->view->sessionErrorForm = $session;

And access it in your view with $this->sessionErrorForm:

<div><input type="text" name="prenom" value="<?php if (isset($this->sessionErrorForm->prenom)): echo $this->sessionErrorForm->prenom; endif;?>" title="Pr&#233;nom *"/>

Or you can declare it in your view and use it like the following:

<?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&#233;nom *"/>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆