Zend Framework : Modular Application [Part 1]

Project description : A simple guestbook module using Zend Framework 1.11 .

Project

Create new project using Zend_Tool :

zf create project MyApp
cd MyApp

Create module :

zf create module Guestbook

Create controller for Guestbook (1 = index action included):

zf create controller Index 1 Guestbook

Now go to /MyApp/application/configs/application.ini and comment/delete the line :

;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

Then add the lines

;Modular suport
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =

And add this lines to set Guestbook as default module

resources.frontController.params.prefixDefaultModule = "1"
resources.frontController.defaultModule = "Guestbook"

Create php file “Bootstrap.php” under folder /MyApp/application/modules/Guestbook and past the code

<?php
class Guestbook_Bootstrap extends Zend_Application_Module_Bootstrap{}

Now test your app

Video :

Comments (14)

SebastianApril 25th, 2011 at 6:01 pm

Great tutorial !
Thank you for your work :)

Jack PetersonApril 27th, 2011 at 10:07 pm

What would the correct approach be for adding multiple modules while still retaining the default module for shared components?

modules/default/* (for shared items like authentication [zend_auth] & authorization [zend_acl], etc)
modules/blog/*
modules/catalog/*

TalofoApril 28th, 2011 at 1:45 pm

So nice!!! Very well explained. You rock! :) Please, when will part 2 be available ??

Thanks you so much again! :)

Cheers!

TalofoApril 28th, 2011 at 1:52 pm

@Jack Peterson: Indeed. I do believe that would be the approach to take.

Edgar MartinezJune 5th, 2011 at 8:21 pm

thank you I think this will help I was stuck and I so prefer the module structure to the default structure I am coming from joomla and everything there is organized into small packages like the moduler layout of zend thanks again for the tutorial I will post back when done

Edgar MartinezJune 5th, 2011 at 10:50 pm

ok that worked fantastic. First try and I was up and running in 3 minutes flat

bprJune 10th, 2011 at 12:21 pm

Great Work! And a great tutorial. The music was ok but that is nothing to talk about.

I actually learned another important feature – that it is possible to execute those commands from the Zend Studio rather than using the CMD : )

Thank you very much for sharing.

Alí SuárezJuly 7th, 2011 at 11:42 pm

First of all thanks.

How do I use a different layout for every module?

SurajitAugust 26th, 2011 at 2:26 pm

hello,
My folder structure is:
projectfolder/zf-tutorial/application/
1. config
2.modules
in modules there are two folder
1. default
2. backend
and under those folder controller,model,views etc are there.
in my contrloller class I extend model class but it showing (model class)class not found

baluAugust 30th, 2011 at 8:25 am

How do I use a different layout for every module?

ApepSeptember 7th, 2011 at 5:20 am

Thank You for Your Tutorial, its very usefull for me.

[...] Zend Tools that creates application/modules/xxmodulenamexx instead. Another I have looked into: ? Zend Framework : Modular Application [Part 1] ? Abdelkader ELKALDI – Web Application Develop… This seems to be the best way, but I don't think you can share models with this one. Also, the [...]

harishJanuary 2nd, 2012 at 5:01 pm

How can i add cron job to run task under index controller everyday

lumiwebMarch 27th, 2012 at 7:04 pm

OUAAAAAHH!!!

Thx your video is perfect, the tutorial is simple, i wish i could help people too one day..
:)

Leave a comment

Your comment