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

DB Templates

 
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
ThermoDust
Smarty Regular


Joined: 10 Sep 2003
Posts: 38

PostPosted: Sun May 02, 2004 8:55 pm    Post subject: DB Templates Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon May 03, 2004 12:44 am    Post subject: Reply with quote

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
View user's profile Send private message
ThermoDust
Smarty Regular


Joined: 10 Sep 2003
Posts: 38

PostPosted: Mon May 03, 2004 1:33 am    Post subject: Reply with quote

didn't help
Back to top
View user's profile Send private message
ThermoDust
Smarty Regular


Joined: 10 Sep 2003
Posts: 38

PostPosted: Mon May 03, 2004 3:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon May 03, 2004 10:24 pm    Post subject: Reply with quote

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 Smile)
Back to top
View user's profile Send private message
ThermoDust
Smarty Regular


Joined: 10 Sep 2003
Posts: 38

PostPosted: Tue May 04, 2004 3:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
ThermoDust
Smarty Regular


Joined: 10 Sep 2003
Posts: 38

PostPosted: Tue May 04, 2004 6:27 pm    Post subject: Reply with quote

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 Smile
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