I've been working hard to get thompsonbd.com ported over to
CakePHP 1.2. Originally, I had a custom build "framework" that I used to string the site together. After having worked with CakePHP at my day job for the past six or seven months, I couldn't wait to bring home the things learned while at the office and try some it out on my own site.
Even after working heavily in a LAMP environment for the past four or five years, I had never heard mention of a PHP framework. When the need arose at my office to start moving our current site off it's old code base and on to something a little newer, we started by looking into CMS's. We quickly found that it was going to be near impossible to find a CMS that could handle the needs of our editors, bloggers, and forum users. That is when we settled on finding a framework to allow us to build our own pieces for the new site.
Here on thompsonbd.com, I obviously get a lot less traffic then we do at work. So some of the things that we at the office don't apply to this site. However, a lot of the conceptual ideas do apply.
We needed a way to be able to use any element, be it a blog roll, latest forum posts, basketball stats box, upcoming football schedule, etc, and use it on any page, blog, forum, etc. We decided that the only way to easily accomplish this was to move all the processing of data out of controllers and into components. Next we decided that every component would have a matching element. These element/component teams have a record in our elements table in our database, along with a pages, areas, holes, and paramaters tables.
Each page has a couple areas assigned to it. These areas allow us to easily move entire groups of elements from one place to another on a layout if needed. Inside each of these areas, we have one hole for each element/component team. This allows use to target each element/component team with specific styling.
So when a page request comes in, we run it through our page controller. This then loads all the areas, holes, componenets, and all the params for the components. Inside each component, we build a single output variable called hole##, ## being the unique identifier from the database for that hole. This variable is an array of two sets of data, a params key and a data key. When we leave the controller headed for the view, we have one variable for each element/component team.
In the view file, we loop through the array of areas and holes and render each element assigned to each hole and give it it's hole variable.
Recently, we have taken this approach a step further and completely removed the styling for each element from the actual element file. We have a number of element templates that are used to do a type of
Smarty templating. This allows our designers to focus on the design aspects of the site, rather than having to learn CakePHP's helpers and how to use them.