views:

80

answers:

1

Hi All,

I'm designing a large web application and I would like to finally be able to modularize the different elements on the page. I'm using the Zend Framework.

I would like to create independent modules that I can combine to create a page(e.g. Contact box, Search Box, Latest blog comments...), sort of how Drupal would do it. These modules will be interactive, so they will obviously contain form and AJAX calls, etc. They will also need a number of views (for rendering how they look) and will also use JS and CSS files.

I've been looking for a standard approach to this problem, but there isn't much concrete information out there. Does anyone know of a resource, book, or webpage that would offer an insight into this kind of design for the web?

Thanks in advance guys :)

+1  A: 

Honestly - I haven't found many resources in my own hunt for this information, but you can get a lot of inspiration to finding your solution by looking at many of the components within Zend Framework itself, particularly Zend_Form. I just made up a "Content" package that has "Element" and "Decorator" hierarchy. The elements themselves can provide their default decorators - and you can attach arbitrary decorators to them (for instance wrapping all your content boxes in <ul class='content'><li>.....</li>.....</ul> style display on one page.

"View Helpers" become very handy, allowing you to do your "latest blog comments" style boxes by calling <?php echo $this->blogComments($article) ?> in the view- which calls My_View_Helper_BlogComments::BlogComments(). I definitely suggest having your own Zend_Form subclasses as well for reusable components that happen to be forms (i.e. contact us being a "My_Form_ContactUs" ).

The "partial" view helper comes in handy as well for abstracting certain parts of display to other reusable files. <?php echo $this->partial('blog/_comments.phtml', null, array('article'=>$article)); ?> - There is a little more overhead used for a partial as it clones a Zend_View.

Handling the JS/CSS includes gets slightly more complicated, what I did was build a static class that you can "require" a "library" which would check to see if that library had already been included, if not - it calls headScript() / headLink() for inclusion of the required files. (used for things like FCKEditor / Sortable / jQuery / etc). Ends up looking like: My_Script::requireLibrary('fckeditor');

gnarf