CARVIEW |
Earn Rewards, Reputation, and Badges
Redeem the reputation points you've earned from participating in O'Reilly Answers for O'Reilly ebooks, videos, courses, and conferences.
Learn more »
Related Questions
Related Posts
Recommended for You
xampp and Smarty
I have just read the very excellent PHP, MySQL & Javascript by Robin Nixon and have got a handle on most things but one thing that has got me stumped is installing Smarty on xampp. This is what I have done so far -
First – my set-up:
I am using xampp 1.7.4 and Smarty 1.0.6 and the server root is c:/xampp/htdocs/
I have the following file set-up:
xampp/htdocs/smarty/Smarty.class.php
xampp/temps/smarty/
templates/
templates_c/test.tpl
cache/
configs/
I have edited the php.ini file , ‘Paths & Directories’ to read:
include_path = “.;c:\php\includes”;“.;C:\xampp\smarty”
I have written a ‘c:/xampp/htdocs/smarty/smarty.php’ file that reads:
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
require "$path/smarty/Smarty.class.php";
$smarty = new Smarty();
template_dir = “$path/temps/smarty/templates”;
$smarty->config_dir = “$path/temps/smarty/templates_c”;
$smarty->cache_dir = “$path/temps/smarty/cache”;
$smarty->compile_dir = “$path/temps/smarty/configs”;
$smarty->testInstall();
//$smarty->utilities->test();
$smarty->assign(‘name’, ‘Ned’);
$smarty->display(“$path/temps/smarty/templates/test.tpl”);
?>
I have also written a ‘c:/xammp/htdocs/temps/smarty/templates/test.tpl’ file that reads:
{* Smarty *}
Hello {$name}, welcome to Smarty!
When I run smarty.php the result I get is:
Smarty Installation test…
Testing template directory…
C:/xampp/htdocs/temps/smarty/templates is OK.
Testing compile directory…
C:/xampp/htdocs/temps/smarty/configs is OK.
Testing plugins directory…
C:\xampp\htdocs\smarty\plugins\ is OK.
Testing cache directory…
C:/xampp/htdocs/temps/smarty/cache is OK.
Testing configs directory…
C:/xampp/htdocs/temps/smarty/templates_c is OK.
Tests complete.
Fatal error: Uncaught exception ‘SmartyException’ with message ‘Unable to load template file ‘C:/xampp/htdocs/temps/smarty/templates/test.tpl” in C:\xampp\htdocs\smarty\sysplugins\smarty_internal_template.php:163 Stack trace: #0 C:\xampp\htdocs\smarty\sysplugins\smarty_internal_template.php(541): Smarty_Internal_Template->isExisting(true) #1 C:\xampp\htdocs\smarty\Smarty.class.php(337): Smarty_Internal_Template->getRenderedTemplate() #2 C:\xampp\htdocs\smarty\Smarty.class.php(381): Smarty->fetch(‘C:/xampp/htdocs…’, NULL, NULL, NULL, true) #3 C:\xampp\htdocs\smarty\smarty.php(24): Smarty->display(‘C:/xampp/htdocs…’) #4 {main} thrown in C:\xampp\htdocs\smarty\sysplugins\smarty_internal_template.php on line 163
Where have I gone wrong?
Regards,
‘H’
5 Replies

Please sign in or register to reply.
Please sign in or register to vote.
Please sign in or register to vote.
Voting for yourself is not allowed.
Voting for yourself is not allowed.




Posted Jul 07 2011 07:52 PM
"C:/xampp/htdocs/temps/smarty/templates/test.tpl"
It should be:
"C:\xampp\htdocs\temps\smarty\templates\test.tpl"
Digital Photography Club
Administrator
Please sign in or register to vote.
Please sign in or register to vote.
Voting for yourself is not allowed.
Voting for yourself is not allowed.

Posted Jul 08 2011 08:54 AM
Thanks for this but - no cigar.
I put in the change you suggested but it has had no effect - I got the following:
Smarty Installation test...
Testing template directory...
C:/xampp/htdocs/temps/smarty/templates is OK.
Testing compile directory...
C:/xampp/htdocs/temps/smarty/configs is OK.
Testing plugins directory...
C:\xampp\htdocs\smarty\plugins\ is OK.
Testing cache directory...
C:/xampp/htdocs/temps/smarty/cache is OK.
Testing configs directory...
C:/xampp/htdocs/temps/smarty/templates_c is OK.
Tests complete.
Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'C:/xampp/htdocs emps\smarty emplates est.tpl'' in C:\xampp\htdocs\smarty\sysplugins\smarty_internal_template.php:163 Stack trace: #0 C:\xampp\htdocs\smarty\sysplugins\smarty_internal_template.php(541): Smarty_Internal_Template->isExisting(true) #1 C:\xampp\htdocs\smarty\Smarty.class.php(337): Smarty_Internal_Template->getRenderedTemplate() #2 C:\xampp\htdocs\smarty\Smarty.class.php(381): Smarty->fetch('C:/xampp/htdocs...', NULL, NULL, NULL, true) #3 C:\xampp\htdocs\smarty\smarty.php(24): Smarty->display('C:/xampp/htdocs...') #4 {main} thrown in C:\xampp\htdocs\smarty\sysplugins\smarty_internal_template.php on line 163
Any other suggestions would be gratefully received.
'H'
Please sign in or register to vote.
Please sign in or register to vote.
Voting for yourself is not allowed.
Voting for yourself is not allowed.

Posted Jul 08 2011 12:03 PM
Php is going to read any '\' as an escape sequence. If you are going to change that directory reference, double those backslashes, ie change the directory to "C:\\xampp\\htdocs\\temps\\smarty\\templates\\test.tpl"
I can see in your new error message that the change got garbled. That will fix it. However, I don't think that it is your problem. Php internally handles the unix/windows path conversions.
Please sign in or register to vote.
Please sign in or register to vote.
Voting for yourself is not allowed.
Voting for yourself is not allowed.



Posted Jul 12 2011 01:59 AM
template_dir = "$path/temps/smarty/templates";
However, as detailed on page 271 of the book this should, in fact, be:
$smarty->template_dir = "$path/temps/smarty/templates";
I haven't checked your code any further as this is likely the main problem.
- Robin.
Please sign in or register to vote.
Please sign in or register to vote.
Voting for yourself is not allowed.
Voting for yourself is not allowed.

Posted Jul 15 2011 07:36 AM
Hi, thanks for looking at this for me. Confession time: I am a dummy and not able to cut-and-paste properly!!
The coding that I have in the smarty.php file is actually -
$smarty->template_dir = "$path/temps/smarty/templates";
So, I am still no further forward and cannot understand where I have gone wrong.
Regards,
'H'
P.S. I ahve also got the version of Smarty wrong - it should read 3.0.6.
![]() © 2011, O'Reilly Media, Inc. (707) 827-7000 / (800) 998-9938 All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners. |
|