phpzend-frameworkbootstrappingzend-controllerzend-framework-modules

Unable to access module forms in module controller


I have a test module. In test module I have a Form in forms folder.

myproject/application/modules/test/forms/TestForm.php

class Test_Form_TestForm extends Zend_Form {
    //form elements
}

myproject/application/modules/test/controllers/TestController.php

class Test_TestController extends Zend_Controller_Action {

    public function indexAction() {
        $this->view->form = new Test_Form_TestForm();  // this is generating error
    }
} // end class

Form initialization in controller is generating following error:

Fatal error: Class 'Test_Form_TestForm' not found in C:\wamp\www\student\application\modules\notification\controllers\NotificationController.php on line 16

How to make this form accessable in controller. Same type of case is working with default controller. I know I have to register my module in bootstrap with Form_ indicator but dont know exact syntax.


Solution

  • You can also initialize multiple modules in a separate function in one Bootstrap file like:

    protected function _initAutoloaders() {
    
            $test_loader = new Zend_Application_Module_Autoloader( array(   'namespace' => 'Test',
                                                                                'basePath'  => APPLICATION_PATH . '/modules/test'
            ));
    
    
          $mynew_loader = new Zend_Application_Module_Autoloader( array(    'namespace' => 'Mynew',
                                                                                'basePath'  => APPLICATION_PATH . '/modules/mynew'
            ));
    }