Squirrel Hacker | I have come forward in time from the year 1986 to share this with you

Apr/09

9

Smarty… again

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. A look at PostgreSQL
  3. When is 4 – 1 = 4?
  4. Templating
  5. links for 2009-02-23

No tags

No comments yet.

Leave a Reply

<<

>>