1

I have a structure like follows:

/application
.....
--/modules
----/structure
------/controllers
--------/indexController.php
------/forms
--------/Department.php //here class Structure_Form_Department extends Zend_Form

in indexController.php

...
public function saveAction()
    {
        $request = $this->getRequest();
        $form = new Structure_Form_Department();//<-- error
....
}

and i get error

Fatal error: Class 'Structure_Form_Department' not found

when try to zf enable form module - receive :

An Error Has Occurred                         
 This project already has forms enabled.

i think this is a config-like problem... but do not understand what i need to do...

EDIT 1

found good solution here

but for some way zend starts repeat executing _init... functions from default bootstrap.php....

Community
  • 1
  • 1
Subdigger
  • 2,166
  • 3
  • 20
  • 42

2 Answers2

12

I was also facing a similar problem few months ago and I got the solution by writing following code :

In application.ini

autoloadernamespaces[] = "Structure_"

In Bootstrap.php

protected function _initAutoload()
    {
        $autoloader=new Zend_Application_Module_Autoloader(array(
                'namespace' => 'Structure',
                'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'Structure'
            ));
    }

And at the index.php

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    realpath(APPLICATION_PATH),
    get_include_path(),
)));

Please let me know if it doesn't works.....

Pushpendra
  • 4,344
  • 5
  • 36
  • 64
  • `/application/bootstrap.php` or `/application/modeules/structure/bootstrap.php` ? – Subdigger Aug 04 '11 at 09:12
  • does not helps ... _Warning: include_once(Structure/Form/Department.php): failed to open stream: No such file or directory..._ – Subdigger Aug 04 '11 at 09:32
  • 1
    ok then... after many hrs spent on this. there is good enough to add `_initAutoload()` to Bootstrap.php but you point me to wrong path. the correct one is `dirname(__FILE__).DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.'structure'` (according to lowercase 's'). but thanks for advice – Subdigger Aug 04 '11 at 11:55
0

I guess adding Application in-front of Structure_Form_Department will work.

ie

Application_Structure_Form_Department()

Or you may want to tell in the config.ini the from appnamespace = "Application" to appnamespace = ''.

I have some piece of code in github. You can see how the modules work.

$contactForm = new Contact_Form_Contact();

Name of form is

class contact_Form_Contact extends Zend_Form

All codes over github. Check it out .

https://github.com/harikt/blog/blob/master/application/modules/contact/controllers/IndexController.php

https://github.com/harikt/blog/blob/master/application/modules/contact/forms/Contact.php

Hari K T
  • 4,174
  • 3
  • 32
  • 51
  • What's the name of the form ? I mean class X_Y_Z extends Zend_Form . – Hari K T Aug 03 '11 at 13:24
  • like here `Fatal error: Class 'Structure_Form_Department' not found` =) – Subdigger Aug 03 '11 at 14:21
  • I guess you are calling the form from controller like `Structure_Form_Department` . Now show me the name of the form you have made which extends the Zend_Form . Is it same ? Else see some code over here https://github.com/harikt/blog/blob/master/application/modules/contact/forms/Contact.php – Hari K T Aug 04 '11 at 10:00
  • form was created by zend tool `class Structure_Form_Department extends Zend_Form` – Subdigger Aug 04 '11 at 10:04