Reintroduction
It's been roughly 2 years since I last hosted a website on this domain (thanks webarchive) and so thought it was high time I put one back up, especially due to all the new fun technologies that are finally emerging to the big time. This sudden urge to put a site back in was *going* to be a quick job, simply install wordpress; whack up a custom style; add some plug-ins and voila!
However mainly due to Steve, I was persuaded into creating my own blog based around the vastly improved cakephp framework. Thank fully it was a fairly fast process to pick up, although getting the smarty templating system to work was a slight head ache, mainly due to me not fully and I must say still not fully understanding how exactly the framework operates. I will go more into this over the coming weeks and I plan at least writing a tutorial based around the original cakephp blog tutorial however with a twist of using smarty as the templating system rather than the default cakephp.
For those of you wondering why I would spend time even attempting to use the smarty system when the cakephp default is quiet adequate. I ask you to think back to the debate regarding table layouts v css based layouts. There will several reasons (size of files, ease of updating, cost in the long run) however the key factor for me was always that a table by its very name is for tabulated data and not infact for page layout. So I ask you, what is PHP? For me it's a server side programming language that allows static HTML pages to become dynamic. Therefore there is no need to mix these two items, as one cannot live without the other but a dynamic page and a static page should still only contain client side languages with a splash of the sections needed to speak with the server side. Smarty does this and in my opinion very well. It allows anyone to be able to read a page and understand what is going on, separating the server side developer script with the front end client script. It does not compromise on speed due to smarty compiling the code into PHP, it has a built in caching system to reduce load along with a caching system, reducing the load still further. Using a specific templating system also reduces repetition of code.
Here's a quick example of a cakephp view and a smarty view.
<?php foreach ($posts as $post): echo '<article>'; echo '<p class="title">'.$post['Post']['title'].' <time>'.$post['Post']['datetime'].'</time></p>'; echo '<div class="entry">'.$post['Post']['content'].'</div>'; echo '</article>'; endforeach; ?>
{section name=dist loop=posts} <article> <p class="title">{$posts[dists][title]} <time>{$posts[dists][datetime]}</time></p> <div class="entry">{$posts[dists][content]}</div> </article> {/section}
Even for a person who can read php, the smarty layout gives at a quick glance an easier method of working out exactly what is happening within that section. It moves PHP towards the pinnacle of all programming languages - pseudo code, which in the long run is what most programmers would prefer their language syntax to resemble.

No Comments