Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Templateing from database

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
har8
Smarty n00b


Joined: 06 Jun 2008
Posts: 4

PostPosted: Fri Jun 06, 2008 4:30 am    Post subject: Templateing from database Reply with quote

Somebody please help me. I want to make smarty template from database and not from file (ex. $smarty->display ('index.tpl')). How can i do it?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Jun 06, 2008 6:20 am    Post subject: Reply with quote

See http://www.smarty.net/manual/en/template.resources.php Example 15-9. If you are using mysql you may have to replace the SQL statements with the corresponding mysql statements.
Back to top
View user's profile Send private message
har8
Smarty n00b


Joined: 06 Jun 2008
Posts: 4

PostPosted: Fri Jun 06, 2008 6:45 am    Post subject: Reply with quote

Thank a lot , but there are some errors like this.

Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'db_get_timestamp' was given in D:\xampp\xampp\htdocs\mynexuslab\lib\smarty\Smarty.class.php on line 1569.

If you can give me some samples please.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Jun 06, 2008 2:56 pm    Post subject: Reply with quote

Plese post your the code of what you have done.
Back to top
View user's profile Send private message
har8
Smarty n00b


Joined: 06 Jun 2008
Posts: 4

PostPosted: Wed Jun 11, 2008 10:50 am    Post subject: Reply with quote

/////////////////////////// index.php /////////////////////////////

$smarty = new Smarty;

$smarty->compile_check = true;
$smarty->debugging = false;

$smarty->compile_dir = $dirname."tmp\\templates_c";
$smarty->template_dir = $dirname."tmp\\templates";
$smarty->config_dir = $dirname."tmp\configs";
$smarty->register_resource("db", array("db_get_timestamp",
"db_get_timestamp",
"db_get_secure",
"db_get_trusted"));


// using resource from php script
$smarty->display("db:index.tpl");


///////////////////// resource.db.php at plugins folder ////////////////////


// put these function somewhere in your application
function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
{
// do database call here to fetch your template,
// populating $tpl_source
$sql = new mySQL();
$sql->query("select theme_description
from themes
where theme_id='1'");
if ($sql->num_rows) {
$tpl_source = $sql->record['tpl_source'];
return true;
} else {
return false;
}
}

function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
// do database call here to populate $tpl_timestamp.
$sql = new mySQL();
$sql->query("select theme_description
from themes
where theme_id='2'");
if ($sql->num_rows) {
$tpl_timestamp = $sql->record['tpl_timestamp'];
return true;
} else {
return false;
}
}

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
}



I can't guess how to do it ((
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Jun 11, 2008 3:48 pm    Post subject: Reply with quote

Okay if you have placed the resource function as resource.db.php at plugins folder you must not use the $smarty->register_resorce methode.

The later is just for the case when the resource functions are within your script and not placed in the plugins folder.
Back to top
View user's profile Send private message
har8
Smarty n00b


Joined: 06 Jun 2008
Posts: 4

PostPosted: Thu Jun 12, 2008 5:24 am    Post subject: Reply with quote

Ok , thanks , but how to template the code from DB ?
for ex.

CREATE TABLE IF NOT EXISTS `themes` (
`theme_id` int(11) NOT NULL auto_increment,
`theme_name` varchar(255) NOT NULL,
theme_description` text character set utf8 collate utf8_unicode_ci,
PRIMARY KEY (`theme_id`),
) ENGINE=MyISAM;

My code is on the theme_description

for ex.

{if 5==5}
TRUE
{else}
FALSE
{/if}

. Now how to create theme_description field as a template Question Please help me I need it a loooooooooot. Thanks.

Regards,
Har8
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP