如果我取消注释以下行,则无法获取$this->_request->getPost('Login')
//$this->setDecorators(array(array('viewScript', array('viewScript' => 'admin/login_decorator.phtml'))));
$this->_request->getPost
适用于表单,但不适用于表单装饰器。
以下是文件......
形式/ loinForm.php
<?php
class Application_Form_LoginForm extends Zend_Form {
public function __construct($options = null) {
parent::__construct($options);
$this->setMethod('post');
$name = new Zend_Form_Element_Text('username');
$name->removeDecorator('Label')
->removeDecorator("HtmlTag")
->addErrorMessage("Please Enter username")
->setRequired(true);
$password = new Zend_Form_Element_Password('password');
$password->removeDecorator('Label')
->removeDecorator("HtmlTag")
->addErrorMessage("Please Enter password")
->setRequired(true);
$submit = new Zend_Form_Element_Submit('Login');
$submit->removeDecorator('Label')
->removeDecorator("HtmlTag");
$this->addElements(array($name, $password, $submit));
//$this->setDecorators(array(array('viewScript', array('viewScript' => 'admin/login_decorator.phtml'))));
}
}
视图/脚本/管理/ login_decorator.phtml
<link href="<?php echo $this->baseUrl(); ?>/css/login.css" media="screen" rel="stylesheet" type="text/css">
<section class="container">
<div class="login">
<h1>Login to Administrator</h1>
<form action="" method="post" enctype="application/x-www-form-urlencoded">
<p><input type="text" name="username" value="" placeholder="Username"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p class="submit"><input type="submit" name="commit" value="Login"></p>
</form>
</div>
<div class="login-help">
<p>Forgot your password? <a href="#">Click here to reset it</a>.</p>
</div>
</section>
login.phtml
<?php echo $this->form; ?>
adminController.php loginAction()
public function loginAction() {
$mysession = new Zend_Session_Namespace('Admin');
if (isset($mysession->adminName)) {
$this->_redirect('/admin');
}
$form = new Application_Form_loginForm();
$this->view->form = $form;
//Preform Admin login action
if ($this->_request->getPost('Login')) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) { //If form data is valid
$name = $this->_request->getPost('username');
$password = $this->_request->getPost('password');
/* * **Creating object of model adminlogin class**** */
$adminLoginObj = new Application_Model_Adminlogin();
$fetchResult = $adminLoginObj->checkAdminAuthority($name, $password);
if (count($fetchResult) > 0) {
$mysession->adminName = $name;
$this->_redirect('/admin/');
} else {
$mysession->failLogin = "Invalid Username or Password!";
$this->_redirect('/admin/login');
}
}
}
}
我无法找出导致此问题的原因。 请帮我解决这个问题。提前谢谢。
答案 0 :(得分:0)
请检查 在你的控制器中 if($ this-&gt; _request-&gt; getPost('Login')){...}
在views / scripts / admin / login_decorator.phtml
中<input type="submit" name="commit" value="Login">
字段名称与操作不匹配。
请相应检查。我希望这会对你有所帮助。