Re: [SMARTY] Custom resources
| From: | boots | Date: | Thu, 04 May 2006 05:11:45 +0000 |
| Subject: | Re: [SMARTY] Custom resources | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-13417@lists.php.net to get a copy of this message | ||
--- Eric Mueller <eric@ericmueller.org> wrote:
> Hi, hoping someone can help me with this. I am working on a custom resource
> handler must be missing something obvious...? Why is this giving me this
> error: "Warning: Smarty error: unable to read resource: "db:blah" in
> C:\htdocs\cms\libs\Smarty.class.php on line 1095"?
>
>
> <?php
>
> require_once('libs/Smarty.class.php');
>
> $smarty = new Smarty;
>
> function db_source($tpl_name, &$tpl_source, &$smarty_obj) {
> $tpl_source = "You asked for $tpl_name.";
> return true;
> }
>
> function db_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) {
> return false; // it's always new
> }
Hi.
You return false only on failure -- ie: you can't determine the timestamp at
all. The implied condition is then that you can't locate the requested resource
item. Otherwise, you should return true and populate $tpl_timestamp with the
proper timestamp. If you want non-expiring templates and don't intend to
look-up the proper timestamp, set the timestamp for $tpl_timestamp to now
(perhaps with time()).
HTH
> function db_secure($tpl_name, &$smarty_obj) {
> // assume all templates are secure
> return true;
> }
>
> function db_trusted($tpl_name, &$smarty_obj) {
> // not used for templates
> return true;
> }
>
>
> // register the resource name "db"
> $smarty->register_resource("db", array( "db_source",
> "db_timestamp",
> "db_secure",
> "db_trusted" ) );
>
> $smarty->display('db:blah');
>
> ?>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com