我想呈现使用Zend_Form登录表单,我希望它呈现调用www.site.com/login或www.site.com/account/login,但一旦我完成下面的所有步骤,我尝试从我的浏览器调用/登录或/帐户/登录我收到HTTP 500(内部服务器错误)..即使该网站的其他部分完美工作。请帮我找出其中我错了..无法呈现Zend_Form
(请注意,我使用Zend Framework 1.11)
(1)通过ZF创建模型
zf create model FormLogin
(2)编辑在应用程序/模型新创建的模型/ FormLogin.php
class Application_Model_FormLogin extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('login');
$this->setMethod('post'); // GET O POST
$this->setAction('/account/login'); // form action=[..]
$email = new Zend_Form_Element_Text('email');
$email->setAttrib('size', 35);
$pswd = new Zend_Form_Element_Password('pswd');
$pswd->setAttrib('size', 35);
$submit = new Zend_Form_Element_Submit('submit'); // submit button
$this->setDecorators(array(array('ViewScript', array('viewScript' => '_form_login.phtml'))));
$this->addElements(array($email, $pswd, $submit));
}
}
(3)添加在loginAction到账户控制器
class AccountController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
}
public function loginAction()
{
$form = new Application_Model_FormLogin();
$this->view->form = $form;
}
}
(4)在创建应用程序/视图/脚本/帐户查看/ login.phtml
<?php echo $this->form; ?>
(5)创建网页应用程序/视图/脚本/ _form_login.phtml由setDecorators称为()在点(2)
<form id="login" action="<?php echo $this->element->getAction(); ?>"
method="<?php echo $this->element->getMethod(); ?>">
<p>
E-mail Address<br />
<?php echo $this->element->email; ?>
</p>
<p>
Password<br />
<?php echo $this->element->pswd; ?>
</p>
<p>
<?php echo $this->element->submit; ?>
</p>
</form>
(6)这是我的bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function _initRoutes()
{
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route_Static (
'login',
array('controller' => 'Account', 'action' => 'login')
);
$router->addRoute('login', $route);
$route = new Zend_Controller_Router_Route (
'games/asin/:asin/',
array('controller' => 'Games',
'action' => 'view',
'asin' => 'B000TG530M' // default value
)
);
$router->addRoute('game-asin-view', $route);
}
}
我觉得你不需要定义默认模块的'控制器/ action'任何路线。 – NAVEED 2012-02-24 14:37:22
即使我删除我的路由,它也不起作用 – evil0 2012-02-24 14:46:26
它应该工作,正如错误所述,它是一个“内部服务器错误”,您的代码对我来说没有任何问题。 – Liyali 2012-02-24 14:49:00