views:

32

answers:

2

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?

A: 

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.

gaoshan88
I tried that, but it didn't work.
Paul
See my edit. That should fix it (note the case of the name of your action).
gaoshan88
I'm getting Fatal error: Class 'Application_Form_Testform' not found, is there a way to display on screen where it's trying to look?
Paul
A: 

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.

David Weinraub
Putting it in that folder and renaming it didn't work for me unfortunately
Paul
Are you declaring/setting a different appnamespace in either a 1. `configs/application.ini` or 2. a `Bootstrap::_initXXX()` method?
David Weinraub