Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
Uncaught exception 'SmartyException' with message 'Unable to

 
Post new topic   Reply to topic    Smarty Forum Index -> Installation and Setup
View previous topic :: View next topic  
Author Message
redbrad0
Smarty Regular


Joined: 03 Feb 2007
Posts: 35

PostPosted: Wed Jan 26, 2011 3:03 am    Post subject: Uncaught exception 'SmartyException' with message 'Unable to Reply with quote

I have been using Smarty 2 for a long time and just uploaded the Smarty 3 files. All my smarty files are stored in a DB instead of in files on the server. Running the test it shows that everything is OK and I can build a sample .php file reading the content from the server but as soon as I add in the database connection it throws the error. Any ideas where to look? I cant seem to find the problem.

// register the resource name "db"
$smarty->registerResource("db", array("db_get_template",
"db_get_timestamp",
"db_get_secure",
"db_get_trusted"));

Quote:
Smarty Installation test...
Testing template directory...
/home/www/domain.com/public_beta/templates is OK.
Testing compile directory...
/home/www/domain.com/public_beta_template_cache is OK.
Testing plugins directory...
/home/www/domain.com/public_beta/includes/plugins/ is OK.
Testing cache directory...
/home/www/domain.com/public_beta/templates_c is OK.
Testing configs directory...
/home/www/domain.com/public_beta/_temp_builder is OK.
Tests complete.


Code:
Fatal error:
Uncaught exception 'SmartyException' with message 'Unable to read template db 'index.tpl'' in /home/www/domain.com/public_beta/includes/sysplugins/smarty_internal_template.php:144
Stack trace:
#0 /home/www/domain.com/public_beta/includes/sysplugins/smarty_internal_templatecompilerbase.php(67): Smarty_Internal_Template->getTemplateSource()
#1 /home/www/domain.com/public_beta/includes/sysplugins/smarty_internal_template.php(260): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))
#2 /home/www/domain.com/public_beta/includes/sysplugins/smarty_internal_template.php(413): Smarty_Internal_Template->compileTemplateSource()
#3 /home/www/domain.com/public_beta/includes/sysplugins/smarty_internal_template.php(558): Smarty_Internal_Template->renderTemplate()
#4 /home/www/domain.com/public_beta/includes/Smarty.class.php(337): Smarty_Internal_Template->getRenderedTemplate()
#5 /home/www/domain.com/public_beta/includes/Smarty.class.php(381): Smarty->fetch('db:index.tpl', N in /home/www/domain.com/public_beta/includes/sysplugins/smarty_internal_template.php on line 144
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Wed Jan 26, 2011 8:43 am    Post subject: Reply with quote

make sure db_get_timestamp() returns a boolean and assigns an integer to the second argument. If the returned timestamp is not an integer, the source will fail
Back to top
View user's profile Send private message Visit poster's website
redbrad0
Smarty Regular


Joined: 03 Feb 2007
Posts: 35

PostPosted: Wed Jan 26, 2011 4:27 pm    Post subject: Reply with quote

globe wrote:
make sure db_get_timestamp() returns a boolean and assigns an integer to the second argument. If the returned timestamp is not an integer, the source will fail


My function is listed below and is returning TRUE and I did an output of the $tpl_timestamp and it is being set as 1294683732 which is Mon, 10 Jan 2011 18:22:12 GMT. In my Cache directory I do see two files.

4cbeb359c70e2c12d7356cc3e5d4d41c0f9983d7.file.index.tpl.php
betastubwirecom^4cbeb359c70e2c12d7356cc3e5d4d41c0f9983d7.file.index.tpl.php


Code:
function db_get_timestamp($tpl_name, $tpl_timestamp, $Smarty_obj)   {
      global $gb;

      /* DATABASE INFO IS REMOVED */
      
    $tpl_timestamp = strtotime($row['LastUpdatedAt']);
   
   
    return true;
}
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Wed Jan 26, 2011 4:31 pm    Post subject: Reply with quote

Code:
function db_get_timestamp($tpl_name, $tpl_timestamp, $Smarty_obj)


must be

Code:
function db_get_timestamp($tpl_name, &$tpl_timestamp, $Smarty_obj)
Back to top
View user's profile Send private message Visit poster's website
redbrad0
Smarty Regular


Joined: 03 Feb 2007
Posts: 35

PostPosted: Wed Jan 26, 2011 11:51 pm    Post subject: Reply with quote

I did this and its still giving the error. The error is in smarty_internal_template.php at the following lines.

if (!$this->resource_object->getTemplateSource($this)) {
throw new SmartyException("Unable to read template {$this->resource_type} '{$this->resource_name}'");
}
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Wed Jan 26, 2011 11:54 pm    Post subject: Reply with quote

is db_get_template() also return boolean true?
Back to top
View user's profile Send private message Visit poster's website
redbrad0
Smarty Regular


Joined: 03 Feb 2007
Posts: 35

PostPosted: Thu Jan 27, 2011 12:03 am    Post subject: Reply with quote

Ok so I got it thanks to you pointing out the db_get_template and what it returned. The fix (incase anyone comes across this topic) is

function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj) {

should be changed to

function db_get_template ($tpl_name, $tpl_source, $smarty_obj) {
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Thu Jan 27, 2011 12:07 am    Post subject: Reply with quote

redbrad0 wrote:
Ok so I got it thanks to you pointing out the db_get_template and what it returned. The fix (incase anyone comes across this topic) is

function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj) {

should be changed to

function db_get_template ($tpl_name, $tpl_source, $smarty_obj) {


actually you want this:

Code:
function db_get_template ($tpl_name, &$tpl_source, $smarty_obj)
Back to top
View user's profile Send private message Visit poster's website
redbrad0
Smarty Regular


Joined: 03 Feb 2007
Posts: 35

PostPosted: Thu Jan 27, 2011 12:20 am    Post subject: Reply with quote

Why do you want the & sign?
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Thu Jan 27, 2011 12:25 am    Post subject: Reply with quote

Code:
function db_get_template ($tpl_name, &$tpl_source, $smarty_obj)
{
  // return the template content via referenced argument
  $tpl_source = '{assign var="foo" value="bar"}{$foo|escape:"html"}';
  // return success state
  return true;
}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Installation and Setup 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