|
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 |
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Sun May 02, 2004 8:55 pm Post subject: DB Templates |
|
|
Well, I got it to read the DB now. And all is good except that it isn't printing the code. Here is the DB Resource code
Code: |
function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
{
global $cnf, $db;
//global $db;
$db->Connect($cnf->hostname, $cnf->username, $cnf->password, $cnf->database);
$query = sprintf('Select source From templates Where name=\'%s\'',
$tpl_name);
$rs = &$db->Execute($query);
if (!$rs) {
return false;
} else {
$tpl_source = $sql->fields['source'];
return true;
}
}
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
global $cnf, $db;
//global $db;
$db->Connect($cnf->hostname, $cnf->username, $cnf->password, $cnf->database);
$query = sprintf('Select timestamp From templates Where name=\'%s\'',
$tpl_name);
$rs = &$db->Execute($query);
if (!$rs) {
return false;
} else {
$tpl_timestamp = $rs->fields['timestamp'];
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
}
|
I'm querying the mysql using adodb for php. I don't get why this isn't working. Is there any way I can see if the template code works?
Also, I'm calling it by doing: Code: | $smarty->display('db:index.tpl'); |
And I know the resource is registered because I don't get any errors saying it can't find the index.tpl. Anyone have any ideas? PLEASE HELP! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon May 03, 2004 12:44 am Post subject: |
|
|
Sorry, didn't look at the whole thing, but if you are using a mysql timestamp, try retrieving:
UNIX_TIMESTAMP(timestamp) as timestamp
just a thought really |
|
Back to top |
|
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Mon May 03, 2004 1:33 am Post subject: |
|
|
didn't help |
|
Back to top |
|
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Mon May 03, 2004 3:46 pm Post subject: |
|
|
Anyone? I know I can call the template outside of the function using the same code found in the fucntion. Just for some reason it isn't printing the source or anything. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon May 03, 2004 10:24 pm Post subject: |
|
|
Well, when I register a resource I have to use function names like:
smarty_resource_<resource>_source
smarty_resource_<resource>_timestamp
smarty_resource_<resource>_secure
smarty_resource_<resource>_trusted
You don't seem to follow that (indeed, you don't even have a "source" function (you seem to name it "get_template"). I'm curious as to how you registered this (apparently you aren't showing everything ) |
|
Back to top |
|
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Tue May 04, 2004 3:57 pm Post subject: |
|
|
Code: | $smarty->register_resource('db', array('db_get_template',
'db_get_timestamp',
'db_get_secure',
'db_get_trusted'));
| That is how it is registered |
|
Back to top |
|
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Tue May 04, 2004 6:27 pm Post subject: |
|
|
Oh my do I feel stupid. I had an error in this code:
Code: | function smarty_resource_db_source ($tpl_name, &$tpl_source, &$smarty_obj)
{
global $cnf;
global $db;
$db->Connect($cnf->hostname, $cnf->username, $cnf->password, $cnf->database);
$query = sprintf('Select source From templates Where name=\'%s\'',
$tpl_name);
$rs = &$db->Execute($query);
if (!$rs) {
return false;
} else {
$tpl_source = $sql->fields['source'];
return true;
}
} |
See what I missed?
Well, Look here: Code: |
$tpl_source = $sql->fields['source'];
|
Still don't see it? Well, I didn't either for 2 days. It was the $sql-> it should of been $rs->. $sql doesn't even exist in my site. So how could it show the source if I don't have the right variable name. Stupid me...
Well, thanks boot for trying to help |
|
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
|
|