Smarty… again

April 9, 2009
By SeanJA

Smarty again.To those who think that smarty prevents you in any way from writting your business logic into a template… watch this…

 
{php}
 
if (!$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
    echo 'Could not connect to mysql';
    exit;
}
 
if (!mysql_select_db('mysql_dbname', $link)) {
    echo 'Could not select database';
    exit;
}
 
$sql    = '"INSERT INTO unsafe_tabel (unsafe_var) VALUES('".$_GET['unsafe']."')";
 
$result = mysql_query($sql, $link);
 
if (!$result) {
    echo "DB Error, could not query the database\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
 
{/php}

I think I might have just put stuff that actually belongs in the model into the view… and unescaped too… oh dear… (that would be template for you smarty folks). So, no, smarty does not disuade you from doing it, infact it seems that they encourage it a bit by providing you with the option to do so via the {php} {/php} tags, instead of forcing you to use {rdelim} {ldelim} all throughout your code instead (which would surely discourage most people). If I can do that, the people who’s site’s you’ve written can surely do that too… and mess up the nice templates that you have made for them (and their databases too). So, please think of another reason to use Smarty, and if you cannot, then why are you using it?

Share and Enjoy:
  • Twitter
  • DZone
  • del.icio.us
  • Slashdot
  • Digg
  • Reddit
  • HackerNews
  • Technorati
  • Google Bookmarks
  • RSS
  • StumbleUpon
  • Yahoo! Buzz
  • LinkedIn
  • Facebook
  • Print
  • PDF
  • email

Related posts:

  1. Smarty Best Practices 1
  2. Templating
  3. When is 4 – 1 = 4?
  4. A look at PostgreSQL
  5. links for 2009-02-23

Leave a Reply

Your email address will not be published. Required fields are marked *

*