Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend framework: Forms in modules

What I want to do:

Create a number of modules with the forms folder inside them.

What I did:

Create a bootstrapper inside the module and added an _initAutoload function with the specific module name as namespace.

For instance, an admin module with the following bootstrapper:

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{

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

}

My question is:

Is this the correct way of doing what I want? - I tried it without having the admin bootstrapper, but it couldn't find my form, until I added the bootstrapper.

Cheers
Chris

like image 857
Chris Skaaning Avatar asked May 21 '10 12:05

Chris Skaaning


People also ask

How do I create a module in Zend Framework?

Create a new PHP class named Module inside the –myapp/module/Tutorial/src/ directory and implement the ConfigProviderInterface. Set Tutorial as the namespace for the Module class. Write a public function getConfig in the Module class and return the configuration file for the Tutorial Module.

What is the use of Zend framework in PHP?

Zend Framework was created to help ensure that the production of PHP-based web-sites is easier and more maintainable in the long term. It contains a rich set of reusable components including everything from a set of Model-View-Controller (MVC) application components to PDF generation classes.

Is Zend framework in PHP?

Zend is an open source PHP framework. It is pure object-oriented and built around the MVC design pattern. Zend framework contains collection of PHP packages which can be used to develop web applications and services. Zend was started by Andi Gutmans and Zeev Suraski.


2 Answers

The autoloader is automatically set up for each module bootstrap. You don't need to configure it manually.

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {}

is all you need.

Then put your forms in /application/modules/admin/forms/.

Admin_Form_Myform extends Zend_Form {...}

For your custom resources, customize resourceAutoloader:

   class Admin_Bootstrap extends Zend_Application_Module_Bootstrap 
   {
        public function _initAuloload() 
        {
             $resourceLoader = $this->_resourceAuloloader;
             // var_dump($resourceLoader);
        }
   }
like image 141
takeshin Avatar answered Sep 28 '22 03:09

takeshin


Remember to add also in your apllication.ini

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resources.modules = ""

like image 37
Samuele Avatar answered Sep 28 '22 03:09

Samuele