[Zend_Form][1.11.1] Error Message Fatal error: Cla

2019-08-18 05:04发布

问题:

I don't speak english fluently (i'm french) so i will be i followed the tutorial here and i got this structure

Application
--Modules
------admin
---------controller
---------views
------etat
---------controller
---------views
------default
---------controller
---------views
--configs
bootstrap.php

My problem is that, when i created my first form and tried to view it in my browser, i got the following error:

Fatal error: Class 'Admin_Form_Login' not found in C:\wamp\www\get\application\modules\default\controllers\IndexController.php on line 14.

Here is my code:

  • My controller : /modules/etat/controller/IndexController.php

    class Etat_IndexController extends Zend_Controller_Action
    {
    
        public function init()
        {
            /* Initialize action controller here */
        }
    
        public function indexAction()
        {
            // action body
            $form = new Etat_Form_InfoAgent();
            $this->view->form = $form;
        }
    }
    

  • My form : /modules/etat/forms/InfoAgent.php

    class Etat_Form_InfoAgent extends Zend_Form
    {
    
        public function init()
        {
            /* Form Elements & Other Definitions Here ... */
            $this->setName('infoagent');
            $this->setMethod('post');
    
            $login = new Zend_Form_Element_Text('matricule');
            $login->setLabel('Matricule:');
            $login->setRequired(true);
            $login->addFilter('StripTags');
            $login->addFilter('StringTrim');
            $this->addElement($login);
    
            $password = new Zend_Form_Element_Password('agence');
            $password->setLabel('Code agence:');
            $password->setRequired(true);
            $password->addFilter('StripTags');
            $password->addFilter('StringTrim');
            $this->addElement($password);
    
            $submit = new Zend_Form_Element_Submit('submit');
            $submit->setLabel('Valider');
            //$submit->style = array('float: right');
            $this->addElement($submit);       
        }
    
    
    }
    

  • My view : /modules/etat/view/script/index.phtml

    <br /><br />
    <div id="view-content">
        <?php echo $this->form; ?>
    </div>
    

  • Configuration file : configs/application.ini

    [production]
    phpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
    includePaths.library = APPLICATION_PATH "/../library"
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    appnamespace = "Application"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    resources.frontController.params.displayExceptions = 0
    
    ;Modular structure
    resources.modules[] =
    
    resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
    resources.frontController.params.prefixDefaultModule = "1"
    
    ;database ressources
    resources.db.adapter = PDO_MYSQL
    resources.db.params.host = localhost
    resources.db.params.username = root
    resources.db.params.password = 
    resources.db.params.dbname = bd_test
    
    [staging : production]
    
    [testing : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    
    [development : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    resources.frontController.params.displayExceptions = 1
    

    I have searched the web for solution but i didn't get it. I saw a post about the same problem on your website (stackoverflow) and i tried to aplly your instructions without solving my problem. i precise that i haven't change the code on my bootstrap and my public/index.php file

    I hope you could help me soon. thx

  • 回答1:

    Make sure you have created a Bootstrap.php in each module directory, which looks like:

    class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
    {}
    

    In which Admin is the name of the module. Also, make sure there is actually a file Login.php inside directory modules/admin/forms with a class Admin_Form_Login