开发者

How can I save a template and download it from the database using smarty template engine

I'm having a hard time saving my template to a database and download the contents to view using Smarty.

I followed the tutorial on Smarty.net on how t开发者_如何学JAVAo make a custom retrieve type.

My original method was save the tpl markup to the db then download it and pass it as a variable to a smarty assigned variable and in my text.pl do something like {$source}

but this parses it as a string and smarty won't compile it.

the tutorial on smarty website didn't help and just leaves me with more questions...

this is what i tried based on the tutorial

function db_get_template($tpl_name, &$tpl_source, &$s)
{
    $tpl_name = "index.tpl";
    $tpl_source = nl2br($defaults->get_default_theme('theme_data'));
    return true;
}
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
{
    $tpl_timestamp = (int)time();
    //$tpl_timestamp = (int)$defaults->get_default_theme('modified_on');
    return true;
}

function db_get_secure($tpl_name, &$smarty)
{
    // assume all templates are secure
    return true;
}

function db_get_trusted($tpl_name, &$smarty)
{
    // not used for templates 
}
$s->registerResource("db", array( 
    "db_get_template",
    "db_get_secure",
    "db_get_trusted"
));
$s->display("db:index.tpl");

i'm not sure where db:index.tpl is being pulled from. I don't know where the markup is suppose to be loaded into...


I feel dirty even suggesting this, but:

Here's a more relevant manual page than the page you were referencing.

In particular, pay attention to the string: prefix to the "filename" passed in the display method call. You can simply pull the template data out of your database (a horrible idea, IMNSHO) and pass it to Smarty that way. No need to build your own custom resource thing unless you really want to do it that way.

I, for one, would urge you to keep it as stupid, ugly and obvious as possible, as to remind yourself about how much of a horrible, no-good idea this is. I'd like to remind you that Smarty compiles to PHP, and placing Smarty code in the database is an effective gateway to arbitrary code execution, a severe security vulnerability.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜