Writing a CMS/Community with Smarty and the Zend Framework Part 1

Update: Since writing this series I have chosen to not work with Zend DB anymore, I’m using PHP Doctrine instead, I have also thrown out Smarty in favor of H2O. Doctrine is a proper ORM which is far superior in functionality to Zend DB, and H2O feels like a much cleaner and more modern templating solution than Smarty.


Background
I’ll make this short so we can get on with the tutorial: The reason I’m making this system is that we use Joomla 1.5 for our CMS related stuff here and Community Builder (A.K.A Joomlapolis) just don’t work very well with 1.5. Alas, for the current project I’m doing we need some basic blog and gallery functionality for each member and as far as I know there is no real replacement for Community Builder. Checking out typo3 alternatives didn’t work out well either. At a quick glance CWT Community didn’t seem to have the features I was looking for, neither did HOI Community. Any Community looked more promising but the alpha status didn’t really excite me.

Tutorial
So the requirements for the system we are going to build are some kind of CMS capability combined with a community. In this first phase each member will have her own simple blog and gallery. The result will not be near as advanced as Joomla, especially when it comes to the admin area. This system will require people with some programming and designing skill to setup in order to get a new site going. Massive amounts of time and effort has been expended to make Joomla a simple thing to install and administer, time I don’t have.

Let’s start with more specific requirements:
1. We need to be able to insert components everywhere, just like in Joomla with the jdoc tag.
2. The designer has to be able to do as much as possible in the Smarty code. The reason for this is that we don’t want this to become some archaic thing that will require a lot of programmer effort to setup for each new project. We want to empower the designer! That this could mean less boring work for us programmers is another matter…

If you know how to instantiate controllers in the Zend Framework you know that #1 can be taken care of by a combination of instantiating controllers and the Smarty insert function. The way this will work is basically identical to the procedure described in the Smarty widget tutorial. The plan for the overall “flow” will look like this:
1. A call is made to the IndexController which is responsible for rendering the main page, for instance with a call to Smarty->display(). It will however assign various variables to the Smarty template which will be used to render other elements.
2. In the Smarty template code we now have Smarty insert functions which will load controllers based on the parameters they get and display the output from these controllers.
3. We also have a main content area that is passed parameters assigned in the IndexController which in turn got these parameters as a result of user interaction.

Source Code

Related Posts

Tags: , ,