Zend Framework无法看到表单文件夹

时间:2014-01-22 09:15:53

标签: php zend-framework

在我的Zend Framework项目中,我有一个表单文件夹,其中有一个表单

class Application_Forms_Loginextends Zend_Form
{
public function init() {
    $this->setMethod('post');
    $username = $this->createElement('text', 'username');
    $username->setLabel('Username')->setAttrib('maxLength', 75);
    $password = $this->createElement('password', 'password');
    $password->setLabel('password:')->setAttrib('maxLength', 75);
    $signin = $this->createElement('submit', 'signin');
    $signin->setLabel("sign in")->setIgnore(true);
    $this->addElements(array(
        $username, $password, $signin
    ));
}

}

我在UserController中使用此类,但出现此错误

Fatal error: Class 'LoginForm' not found in

编辑:

 public function loginAction() {
    $users = new Application_Model_Users();
    $form = new Application_Forms_Login();
    $this->view->form = $form;
}

现在我收到此错误

Warning: include_once(Application/Forms/Login.php): failed to open stream: No such file or directory in /home/myFolder/public_html/library/Zend/Loader.php 

编辑:添加了项目结构

project structure

4 个答案:

答案 0 :(得分:1)

你的错误说明了一切 你说你有form个文件夹,但你使用的是LoginForm

假设您使用的是zf1,

并且您的表单文件夹正在应用中,

你应该像这样使用它,

class Application_Forms_LoginFrom extends Zend_Form

它可以根据您的文件夹名称。

还将控制器中的呼叫更改为

  $form = new Application_Forms_LoginForm();

根据您的文件夹名称,您是使用Application_form还是Application_Forms

我知道啊 现在你正在使用,

class Application_Forms_Loginextends Zend_Form

可能有拼写错误,你忘记了登录和扩展之间的空间,

试试这个,

 class Application_Form_Login extends Zend_Form

答案 1 :(得分:0)

类Application_Forms_Loginextends Zend_Form它应该是类Application_Form_Login扩展Zend_Form

答案 2 :(得分:0)

应该是:

class Application_Form_Login extends Zend_Form
{
public function init() {
    $this->setMethod('post');
    $username = $this->createElement('text', 'username');
    $username->setLabel('Username')->setAttrib('maxLength', 75);
    $password = $this->createElement('password', 'password');
    $password->setLabel('password:')->setAttrib('maxLength', 75);
    $signin = $this->createElement('submit', 'signin');
    $signin->setLabel("sign in")->setIgnore(true);
    $this->addElements(array(
        $username, $password, $signin
    ));
}

并在您的控制器操作中:

$form = new Application_Form_Login();

如果错误仍然存​​在,请检查application.ini是否为appnamespace =“Application”

答案 3 :(得分:0)

在Zend Framework中,默认的appnamespace配置值为Application

为您的班级Application_Form_Login命名,而不是Application_Forms_Login,并且没有任何问题。

class Application_Form_Login extends Zend_Form
{
    public function init() {
        $this->setMethod('post');
        $username = $this->createElement('text', 'username');
        $username->setLabel('Username')->setAttrib('maxLength', 75);
        $password = $this->createElement('password', 'password');
        $password->setLabel('password:')->setAttrib('maxLength', 75);
        $signin = $this->createElement('submit', 'signin');
        $signin->setLabel("sign in")->setIgnore(true);
        $this->addElements(array(
            $username, $password, $signin
        ));
}

希望有所帮助