May 5, 2008

Zend framework and modules

Categorie: Tech — Tags: , , , , — bise, 11:15 am

Because it took me about 3 hours to figure out how this works, I think someone might find this helpful..
For another projekt i’m curently working on, I decided to use the Zend Framework. I wanted to use the standard router, but splitt the structure into different modules.

Well, there should be a common folder tree like

application
…… modules

………… module1
……………… controllers

……………… view

………… module2
……………… controllers

……………… view

library

public

The first mistake I did, was not to read the reference guide that carefuly.
As you you know you have to name your standard controller class like “IndexController“, but the controller of a modul has to have a prefix. So for the first modul it has to be “Modul1_IndexController“.
While this is well documented I ran into an other stupid mistake:

I also renamed the “controller file” in this way: Module1_IndexController.php. Which is definitly wrong :) It still has to be IndexController.php.

An Example:

$frontController = Zend_Controller_Front::getInstance();

$frontController->setParam(’useModules’, true);
$frontController->setDefaultControllerName(’notindex’);
// if your default controller is not ‘index’

$frontController->throwExceptions(true); //throws exeptions

$frontController->addModuleDirectory(’./application/modules’); //auto find modules

$frontController->dispatch();
//run

modul1: http://yourdomain.com/modul1
or: http://yourdomain.com/modul1/notindex/index

It’s pretty basic.
Zend Framework

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment