|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jovenshadow11 Smarty Rookie
Joined: 28 Jun 2011 Posts: 14
|
Posted: Tue Jun 28, 2011 7:47 am Post subject: template save in the database error |
|
|
Hello guys, i am new to this smarty template engine and i want to make a template that are save to database, ive seen couple of sample but they are not working and i always get this error message.
Fatal error: Call to a member function resource() on a non-object in D:\joven\website\atic\website\development\website\test.php on line 37
i want to know whats missing or mistake in doing on my code below, btw this code is copied on sample i found on the net.
<?
require('plugins/Smarty-3.0.8/libs/Smarty.class.php');
function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj) {
//get the template from the database
/*$q = mysql_query("SELECT template_data FROM template_table WHERE template_name = '$tpl_name'");
if (mysql_num_rows($q)) {
$tpl_source = stripslashes(mysql_result($q,0,"template_data"));
mysql_free_result($q);
return true;
} else {
return false;
}*/
$tpl_source = "this is the template i made from the database";
}
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) {
//get the timestamp of the template
//you can either get it form your db you just set the current time.
$tpl_timestamp = (int)$templates['last_edited'];
return true;
}
function db_get_secure($tpl_name, &$smarty_obj) {
// assume all templates are secure
return true;
}
function db_get_trusted($tpl_name, &$smarty_obj) {
// not used for templates
}
$smarty = new Smarty;
//register the resource
/*$tpl->registered_resources("db", array("db_get_template",
"db_get_timestamp",
"db_get_secure",
"db_get_trusted"));*/
$smarty->register->resource('db', array(
'db_get_template',
'db_get_timestamp',
'db_get_secure',
'db_get_trusted'
));
$template_name = "test_temp_dbase.tpl";
$content = $smarty->fetch("db:{$template_name}");
$smarty->assign('content', $content);
?>
i'll appreciate any help from you guys.... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|