在Zend中创建简单表单的问题

时间:2011-07-14 06:42:08

标签: zend-form

我是Zend Framwork(MVC)的新手。我想用一些HTML控件来创建一个简单的表单。

我创建了一个控制器IndexController,代码如下:

<?php

class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body

        /*$this->view->var = 'User Login Page';*/
        $form = new Form_Login();

        $this->view->form=$form;
    }
}

我的表格代码在application / forms / Login.php中:

<?php

require_once('Zend/Form.php');
class Form_Login extends Zend_Form
{
    public function init()
    {
        parent::__construct($options);

        // the code bellow will create element
        $username = $this->CreateElement('text','username');
        $username->setLabel("Username:");

        // and
        $submit= $this->CreateElement("submit","submit");
        $submit->setLabel("Submit");

        // now add elements to the form as
        $this->addElements(array(
            $username,
            $submit
        ));
    }
}

?>

当我运行这个项目时,它会显示如下错误:

**Fatal error: Class 'Form_Login' not found in C:\xampp\htdocs\LoginForm\application\controllers\IndexController.php on line 16**

请帮帮我......

由于 的Pankaj

1 个答案:

答案 0 :(得分:0)

一切看起来都不错,请确保您的Login.php文件将此作为第一行:

<?php
class Form_Login extends Zend_Form
{
    public function init()

如果这没有帮助,您可能需要检查index.php / Bootstrap.php文件和服务器配置,以确保所有路径都正确。