【发布时间】:2012-03-26 10:55:41
【问题描述】:
我对 Zend 框架有一点经验,但我喜欢摆弄它,直到它工作为止。 但是现在我无法解决这个问题。
我有一个表格:
<?php
class Application_Form_Login extends Zend_Form
{
protected $notEmpty;
public function init()
{
// Create NotEmpty validator
$notEmpty = new Zend_Validate_NotEmpty();
// Configure validators for username element
$notEmpty->setMessage('Gelieve dit veld in te vullen');
$this->setMethod('post');
// emailAddress
$this->addElement('text', 'emailAddress', array(
'filters' => array('StringTrim', 'StringToLower'),
'required' => true,
'validators' => array(
array('validator' => $notEmpty),
),
'label' => 'Emailadres:'
));
// password
$this->addElement('password', 'password', array(
'filters' => array('StringTrim'),
'required' => true,
'validators' => array(
array('validator' => $notEmpty),
),
'label' => 'Wachtwoord:'
));
// submit
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Inloggen'
));
}
}
一个视图:
<?= $this->form ?>
<?= $this->postdata ?>
还有一个 AccountController:
<?php
class AccountController extends Zend_Controller_Action
{
public function init()
{
echo 'data:'.$this->getRequest()->getPost('emailAddress');
/* Initialize action controller here */
}
public function indexAction()
{
$this->view->postdata = var_dump($this->getRequest()->getParams());
$form = new Application_Form_Login();
$request = $this->getRequest();
if ($request->isPost()){
// THIS POINT IS NEVER REACHED
if ($form->isValid($request->getPost())){
if ($this->_isValidLogin($form->getValues())){
// Succes Redirect to the home page
$this->_helper->redirector('index', 'home');
}
else // Not succes Redirect to account page
{
$this->_helper->redirector('index', 'account');
}
}
如您所见,我发表了一条评论:// 永远不会达到这一点。 这个控制器中还有更多功能,但这些与我的问题无关。
让我们再解释一下。 非常奇怪的行为是,当我将数据放入字段时, $this->view->postdata = var_dump($this->getRequest()->getParams() 不返回 POST 数据。 但是当我在登录表单字段中添加注释时,我会看到 POST 数据。当然是空的。 像这样:
array
'controller' => string 'account' (length=7)
'action' => string 'index' (length=5)
'module' => string 'default' (length=7)
'emailAddress' => string '' (length=0)
'password' => string '' (length=0)
'submit' => string 'Inloggen' (length=8)
因此,当没有在登录表单字段中输入任何数据时,实际上不会到达 //THIS POINT IS NEVER REACHED :-)
问题是,我做错了什么?我是否以错误的方式处理 Zend_Controller_Request_Http?
如果您需要更多信息,我应该提供。
【问题讨论】:
标签: php zend-framework zend-form