View previous topic :: View next topic |
Author |
Message |
har8 Smarty n00b
Joined: 06 Jun 2008 Posts: 4
|
Posted: Fri Jun 06, 2008 4:30 am Post subject: Templateing from database |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
har8 Smarty n00b
Joined: 06 Jun 2008 Posts: 4
|
Posted: Fri Jun 06, 2008 6:45 am Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Jun 06, 2008 2:56 pm Post subject: |
|
|
Plese post your the code of what you have done. |
|
Back to top |
|
har8 Smarty n00b
Joined: 06 Jun 2008 Posts: 4
|
Posted: Wed Jun 11, 2008 10:50 am Post subject: |
|
|
/////////////////////////// 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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jun 11, 2008 3:48 pm Post subject: |
|
|
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 |
|
har8 Smarty n00b
Joined: 06 Jun 2008 Posts: 4
|
Posted: Thu Jun 12, 2008 5:24 am Post subject: |
|
|
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 Please help me I need it a loooooooooot. Thanks.
Regards,
Har8 |
|
Back to top |
|
|