Page 1 of 1
The Template Engine Hype? Which one?
Posted: Mon Sep 10, 2007 4:04 am
by josamoto
There are many template engines / frameworks for PHP out there. To name a few:
- Zend Framework -
http://framework.zend.com
- Code Ignigter -
http://www.codeignigter.com
- Cake PHP -
http://www.cakephp.org
- Smarty -
http://smarty.php.net
- PEAR -
http://pear.php.net
and I believe many more.
Which are the most popular / best to use, being both lightweight and easy to learn? I understand that much of it comes down to your own preference, but in generally speaking I'd like some opinions on which one to use, as I feel overwhelmed by the amount of engines available.
Is there an online comparison on the different frameworks?
Posted: Mon Sep 10, 2007 4:14 am
by Christopher
Those things are all a little different. Zend, Cake and Code Igniter are frameworks -- some with class libraries. Smarty is a template library. PEAR is a class library that contains several template libraries and many other classes.
What are you looking for?
Posted: Mon Sep 10, 2007 4:45 am
by josamoto
I need a MVC sort of thing, but not something with a million-and-one classes. Also looking at the URL parsing abilities of CodeIgniter, as well as functions for making my everyday tasks in PHP easier and have development go much quicker. CodeIgniter has shorthand tags for PHP for example you can use <:=funkyChicken?>. I basically want JSP custom tags, but in PHP.
My main interest is in separating my application logic from my template / user-interface, i.e. MVC (Model + View + Controller). A lot of the code we develop gets reused a lot, as we develop websites for estate agents. Currently all 300 sites have a copy of it's own application logic. So if a bug appears, we have to fix it in 300 instances of code.
I want to revamp the code so its all central with also a central database, but each agent has their own website template, which draws information related to their site from the central database using centralized code. One instance of code will make the project easier and allow us to create a portal as well as maintain the code, supply bug fixes and develop add-ons across the board. Also one database is used across multiple agents where their data is separated by means of a unique agent ID.
Basically I need a RAD strategy, and at current, CodeIgniter looks the best for me. PEAR and Zend Framework are too expansive, I do suppose it has been around for a while so more code has been developed.
Posted: Thu Sep 27, 2007 10:43 am
by GeXus
This is what I use, very simple way to separate logic and no added baggage. Essentially you will create a 'templates' folder, then you will have two pages, for example index.php will have a corresponding templates/index-tpl.php, all display logic gets put into the template, and business into the index.php.
Code: Select all
<?
/**
* set() - sets a variable to be used in the template
* display() - includes the template file (FILENAME-tpl.php)
*/
class templates{
function set($name, $value){
$this->vars[$name] = $value;
}
function display(){
if(isset($this->vars)){
extract($this->vars);
}
$page = basename($_SERVER['SCRIPT_FILENAME']);
$page = str_replace('.php','', $page);
$template = $page . '-tpl.php';
return include('templates/'.$template);
}
}
?>
Posted: Thu Sep 27, 2007 8:27 pm
by Ambush Commander
As for a template engine, use XSLT. It forces you to marshal your data into a content neutral format (XML/DOM) and then lets you convert it to HTML or whatever else you want. Template-based solutions still don't do a good enough job of enforcing business/presentation logic separation without strong developer discipline.
Posted: Thu Sep 27, 2007 10:25 pm
by s.dot
I've had great successes with Template Lite. Love it.