0
votes

I have tried setting up a zend site with the following directory structure :

application
  -configs
  -forms
  -modules
     -admin
     -default
        -controllers
           -IndexController.php
        -forms
           -Testform.php
        -layouts
        -modules
        -views

Then in my IndexController.php I have the following

public function contactMeAction() {

    $request = $this->getRequest();
    $form    = new Form_Testform();

    if ($this->getRequest()->isPost()) {
        if ($form->isValid($request->getPost())) {

//process stuff

            return $this->_helper->redirector('index');
        }
    }

    $this->view->form = $form;

}

in the file Testform.php I have

class Form_Testform extends Zend_Form { public function init() { ......etc

But i'm getting the following error :

Fatal error: Class 'Form_Testform' not found in /home/websites/test.local/public_html/prototype/application/modules/default/controllers/IndexController.php on line 22

Call Stack: 0.0004 325228 1. {main}() /home/websites/test.local/public_html/prototype/public/index.php:0 0.1742 5351472 2. Zend_Application->run() /home/websites/test.local/public_html/prototype/public/index.php:28 0.1742 5351472 3. Zend_Application_Bootstrap_Bootstrap->run() /opt/ZendFramework-1.10.7/library/Zend/Application.php:366 0.1745 5351708 4. Zend_Controller_Front->dispatch() /opt/ZendFramework-1.10.7/library/Zend/Application/Bootstrap/Bootstrap.php:97 0.1872 5707240 5. Zend_Controller_Dispatcher_Standard->dispatch() /opt/ZendFramework-1.10.7/library/Zend/Controller/Front.php:954 0.2026 6016200 6. Zend_Controller_Action->dispatch() /opt/ZendFramework-1.10.7/library/Zend/Controller/Dispatcher/Standard.php:295 0.2029 6020692 7. IndexController->contactMeAction() /opt/ZendFramework-1.10.7/library/Zend/Controller/Action.php:513

Where am I going wrong?

3

3 Answers

1
votes

Basically ZF is not finding the form where it expects it to be. I think you need to have the form in application/forms, not in application/modules/default/forms like you do.

Then have it as:

Application_Form_Testform extends Zend_Form

instead of

Form_Testform extends Zend_Form

---EDIT---

So in application/forms you have the file Testform.php That file looks like:

class Application_Form_Testform extends Zend_Form { 
// form code
}

In your controller you have (note the naming of the action... contactmeAction, not contactMeAction):

public function contactmeAction {
    $form = new Application_Form_Testform();
    $this->view->form = $form;
}

Then in your view contactme.phtml:

echo $this->form;

This should work. If it doesn't I would check spelling, capitalization in your action name and make sure things are in the correct path.

0
votes

This is an issue of getting the following things all aligned/consistent:

  1. namespacing
  2. class naming conventions
  3. class file location

If you wish to put your form in the folder application/modules/default/forms, then name the class Default_Form_Testform.

0
votes

Check names/namespaces as gaoshan88 says (must be "class Application_Form_Testform extends Zend_Form" and "$form = new Application_Form_Testform()"; )

Check that your application/configs/application.ini contains these lines:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultModule = "default"
resources.modules[] = ""

Finally create an empty Bootstrap.php file and put it in application/modules/default/ directory.