Zend Form class not found error

2019-07-24 22:23发布

问题:

I am getting this error what should I do ?

Fatal error: Class 'forms_AuthForm' not found in C:\dev\workspaces\
adxweb\application\adxsearch\modules\account\controllers\
AuthController.php on line 26

I have one AuthForm.php in forms folder and Authcontroller.php in controllers folder, and auth.phtml in scripts folder.

Thanks kiran

回答1:

The default path for forms in ZF projects is APPLICATION_PATH/forms, like this:

-- application
    -- forms
        AuthForm.php
    -- models
    -- modules
        -- account
            -- controllers
                AuthController.php
            -- views
                -- helpers
                -- scripts
                    -- auth
                        index.phtml
                        ...

If you wish to place your forms elsewhere, you will need to tell Zend where that location is (it can be done in the bootstrap or, I think, in application.ini).

Also, make sure your classes are named appropriately, as they reflect the paths to the files they're contained in. The names are case sensitive.

[EDIT]

Read this article: http://bsagols.wordpress.com/2010/08/12/zend_loader_autoloader-stand-alone-and-modular-approaches/ - it describes what you appear to be after (modular approach, with per-module forms).

This is the long way around though. The way I'd solve it is moving your forms to application/forms. You can create module-specific folders there, like this:

--application
    -- forms
        -- Auth
            Auth.php

You form class name would then be Namespace_Form_Auth_Auth, where Namespace is your application namespace. This approach requires no modifications to the bootstrap or application.ini.



回答2:

Try $form = new Application_Form_AuthForm() instead of $form = new forms_AuthForm() in your controller file AuthController.php

and make sure that you have class Application_Form_AuthForm extends Zend_Form in your forms/authform.php.

If you want to remove the namespace Application then in your application.ini file set appnamespace = "Application" to appnamespace =



回答3:

If you use modular directory structure:

// application/modules/modulename/forms/Name.php
class Modulename_Form_Name extends Zend_Form {
   public function init() {
     $this->addElements(array(/** */));
   }
}

Then no additional setup is needed, except resources.modules[]= in application.ini and a module bootstrap for modulename module.