Richard Davey said:
> CdV> I don't understand... how is this:
> [snip]
> CdV> Better than this?
> CdV> =================
> CdV> $result = mysql_query ("SELECT * FROM users WHERE id =
> '".$_GET["id"]."');
> CdV> $row_array = mysql_fetch_array ($result);
> CdV> $name    = $row_array["name"];
> CdV> $address = $row_array["address"];
> CdV> $state   = $row_array["state"];
> CdV> $include("template.tpl");
> CdV> ---
> CdV> <html>
> CdV> <body>
> CdV> Name: <?=$name;?><br>
> CdV> Address: <?=$address;?><br>
> CdV> State: <?=$state;?><br>
> CdV> ...
> CdV> =======================
>
> Because you're injecting variables directly into your HTML, which some
> of the time might be ok - but what if the $row_array doesn't contain
> "name" ? You'll raise an Error Warning without first passing it
> through some kind of test (or function).

A good point.  Alternatively I could write error handling myself or
include a library/class.  This is where, in my opinion, Smarty shines, but
is not significantly different than other libraries/classes.

> You assume that the PHP short-tags are enabled (<? ?>) for
> echoing variables and while most the time they are, you shouldn't bank
> on it in code (incidentally, you don't need the trailing ; on the
> short-tag echos).

I was waiting for someone to ding this :-)  I have been used to using
<?php echo $variable; ?>.

> Sure - these things can be fixed easily, but then that isn't the point
> - if you think about it logically, anything Smarty can do, PHP can do
> too (well, duh! :)
>
> But what if you want to take your template and perform a bit more than
> just mere variable substitution on it? How about highlighting all
> words that match a search term, or applying logic to a display block
> based on a user status?

Another good point.  But by writing it myself or including some other
library/class I could have the same functionality.  There again, Smarty is
a great library, and I'll use it when I need it.

> Personally I don't use smarty*, but even I can see the benefits it
> offers.

Me too.  It's likely I'll use it in the future.

/dev/idal

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to