0

在我的控制器中,我尝试在将变量发送到视图之前将其保存在会话中:

session_start();
$_SESSION['prenom'] = $form['prenom'];

$this->_view->prenom = $_SESSION['prenom'];

$this->_redirect('inscription');

然后在我看来我需要显示它:

<div><input type="text" name="prenom" value="<?php if (isset($prenom)){echo $prenom;}?>" title="Pr&#233;nom *" class="small"/>

在此先感谢您的帮助

4

4 回答 4

2

对于初学者,让我们保持一致并使用 Zend 框架。

//session_start();
//$_SESSION['prenom'] = $form['prenom'];  BECOMES
$session = new Zend_Session_Namespace('name'); //will automatically call session_start if required
$session->prenom = $form->getValue('prenom');//assumes $form is a valid Zend_Form object

//$this->_view->prenom = $_SESSION['prenom']; BECOMES
$this->view->prenom = $session->prenom; //$this->_view isn't a thing as far as I know
//if you are expecting the view variable to work after redirect... it won't
//$this->_redirect('inscription'); MAY BECOME
$this_forward('inscription');//will call new action without resetting the request

现在查看脚本:

//assumes you are in the correct view script
//when accessing variables passed to the view, use $this
<input type="text" name="prenom" value="<?php 
if (isset($this->prenom) { 
    echo $this->prenom;
}
?> " title="Prenom *" class="small"/>
于 2012-09-22T07:10:19.427 回答
1

重定向方法重置设置的变量。你必须改变你的看法。就像是:

$this->_helper->viewRenderer('action-name-here');

注意:如果您使用 Zend Framework,请不要使用本机会话方法,请使用Zend_Session.

于 2012-09-21T14:21:22.743 回答
0

<div><input type="text" name="prenom" value="<?php if (isset($_SESSION['prenom'])) { echo $_SESSION['prenom']; }?>" title="Pr&#233;nom *" class="small"/>

于 2012-09-21T14:27:19.213 回答
0

当您使用重定向方法时,会发生实际的 HTTP 重定向(页面重新加载),因此您的所有变量都将被重置。我认为您正在寻找转发方法

于 2012-09-21T14:27:47.937 回答