New GreeneCountyIndiana.com CMS: Modularity
Posted on : 08-07-2008 | By : Chuck | In : HTML/CSS, MySQL, PHP, Programming
0
Modularity is a very important part of writing software. A modular program will contain various ‘modules’ for different functions used throughout the projects.
The CakePHP framework (which the CMS is being built on) makes it easy to write modular code, by use of helpers, components, behaviors, and elements. For those unfamiliar with Cake, it is a MVC framework written for PHP. Helpers and elements are used for views, behaviors for models, and components for controllers.
The past few days have been spent writing various modules for the new CMS. The Tagging system makes use of the Tag Helper, which handles displaying tag lists and the adding/deleting of tags. The Basics Helper has convenience functions for pre-configured pagination and various dialog boxes.
The greatest advantage of helpers is the re-usability in code. For example, the following code:
<php
echo $basics->setupDeleteDialog(array('elementToDelete' => 'div.newsitem'));
?>
is all that is needed to handle the Delete Item dialog. I just add that to the view for each controller (News, Pages, Photos, etc), change the elementToDelete, and viola! I now have a functional delete dialog. If I want to make changes to the way the dialog functions, I merely have to edit the code in the helper file, as opposed to editing code in every single file that contains a delete dialog.
The current CMS makes little to no use of helpers, which makes it extremely difficult to update parts of the website. Fortunately, the new CMS is actually being built with modularity in mind.




