我正在使用 Zend 1.12
我的表单有两个字段:电子邮件和文件
我的索引视图显示了表单。验证成功后,我想解析csv文件并在结果视图上显示内容:
我的代码:
IndexController:
class IndexController extends Zend_Controller_Action {
public function init() {
/* Initialize action controller here */
}
public function indexAction() {
// action body
$form = new Application_Form_FileUpload();
$form->submit->setLabel('Upload');
$this->view->form = $form;
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$file = $form->getValue('file');
$email = $form->getValue('email');
//$this->_helper->viewRenderer('result', null, true);
//$this->_helper->redirector('result', 'index','', array('email' => $email, 'file' => $file));
$this->_helper->redirector->gotoRouteAndExit (array(
'controller' => 'index',
'action' =>'result',
'name' => $file));
} else {
$form->populate($formData);
}
}
}
public function resultAction() {
$email = $this->_getParam('name');
$this->view->email = $email;
}
}
我的索引视图:
<?php
$this->form->setAction($this->url(array('action' => 'index')));
echo $this->form;
?>
我的结果视图:
<?php
echo $this->email;
//echo the content of the csv file;
?>
我的结果视图始终为空。
获取表单数据的正确/正确方法是什么,如果验证成功,则在结果视图中显示内容。
编辑:我已成功将参数传递给resultaction。 我只是在查看不同的文件。这就是它没有出现的原因。
但是,对我的案子来说,这是正确的方法吗?因为它似乎不正确。