私はzendフレームワークを使用しており、zendフォーム、MVC、およびOOPを使用して簡単なログインフォームを出力しようとしています。
私のコードは以下のとおりです。ControllerIndexController.php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$this->view->loginForm = $this->getLoginForm();
}
public function getLoginForm()
{
$form = new Application_Form_Login;
return $form;
}
}
これはフォームです:Login.php
class Application_Form_Login extends Zend_Form
{
public function init()
{
$form = new Zend_Form;
$username = new Zend_Form_Element_Text('username');
$username
->setLabel('Username')
->setRequired(true)
;
$password = new Zend_Form_Element_Password('password');
$password
->setLabel('Password')
->setRequired(true)
;
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Login');
$form->addElements(array($username, $password, $submit));
}
}
そしてビュー:index.phtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<div id="header">
<div id="logo">
<img src="../application/images/logo.png" alt="logo">
</div>
</div>
<div id="wrapper">
<?php echo $this->loginForm; ?>
</div>
</body>
</html>
私はZendFramework、MVC、OOPを初めて使用するので、これはオンラインのアドバイスやチュートリアルなどに続く最善の試みです。