How to solve class not found error in zend framework

While working with Zend_Forms and Zend_Model you must experience the class not found error .

1
2
Fatal error: Class 'form_myFormName' not found
in C:xampphtdocszendfapplicationcontrollersUserController.php on line 17

This is only because of  wrong class name specified by you.Following are the rules that you

should follow while working with zend from and models.

(STEP-1) Write the default setting in Bootstrap.php file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
   protected function _initAutoload()
   {
            $moduleLoader = new Zend_Application_Module_Autoloader(
 
                                         array(   
 
                                              'namespace' => '',   
 
                                              'basePath' => APPLICATION_PATH
                                              ));   
 
              return $moduleLoader;
     }
}

 

Rules for Zend_Form

1.The Default name space in zend framework for Zend_Form is Form and it will pointing to folder named as forms .

So you should keep all you form classes inside forms directory.

2.Your form class name should start with namespace as Form_

3.Always follow the camel shape on naming convention while deciding the file name as well as the class name

4.Create a file inside the forms directory as myFormName.php . This will be your Form class file.

5.Inside myFormName.php create a class as Form_myFormName.php

 

(STEP-2)

myFormName.php

—————————————————————-

1
2
3
4
5
6
7
class Form_myFormName extends Zend_Form
{
      public function init()
      {
          //your form codes goes here like creating form elements
      }
}

(STEP-3)

Then in your controller file write down following code to get a instance of your defined form class

1
2
3
4
5
6
7
8
class UserController extends Zend_Controller_Action
{
    public function indexAction()
    {
       $form = new Form_myFormName();
       $this->view->form = $form;
    }
}