Re: store templates files in SQL
| From: | Monte Ohrt | Date: | Tue, 16 Oct 2001 21:04:26 +0000 |
| Subject: | Re: store templates files in SQL | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1705@lists.php.net to get a copy of this message | ||
read this section:
http://www.phpinsider.com/php/code/Smarty/docs/x548.htm
Specifically "Templates from a function call"
Bertrand DUNOGIER wrote:
>
> Yes, you probably have to modify that function to have it read the
> template in a DB...
>
> The original function looks like this...
>
> function _read_file($filename)
>
> {
> if (!($fd = fopen($filename, 'r'))) {
> $this->_trigger_error_msg("problem reading '$filename.'");
> return false;
> }
> flock($fd, LOCK_SH);
> $contents = fread($fd, filesize($filename));
> fclose($fd);
> return $contents;
> }
>
> So, instead of
> if (!($fd = fopen($filename, 'r'))) {
> you would have something like
> if (!result = mysql_query("select tpl from db where condition")) {
> to get the same error message when the template can not be found
>
> Then... instead of
> $contents = fread($fd, filesize($filename));
> sthg like
> if ($row = mysql_fetch_array($result)) {
> $this->_trigger_error_msg("problem reading '$filename.'");
> return false;
> }
> so that smarty does not crash upon a database error
>
> Then finally
> $contents = $row["tpl"];
> return $contents;
>
> I didn't try, this is just "on the mail" coding :)
>
> Bertrand (aka Katana on EFNet :p)
>
> SJA> Does anyone know how or have a function to store the template files in
> SJA> an SQL database.
>
> SJA> I've looked at the smarty code an I believe this is the function that
> SJA> would have to be changed.. _read_file($resource_name)..
>
> SJA> Thanks in advance.
>
> ---
> You are currently subscribed to smarty as: monte@ispi.net
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at
> http://www.phpinsider.com/php/code/Smarty/
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/