Page 1 of 1

xampp and Smarty

PostPosted: 26. June 2011 07:48
by Hamish
Hi Guys,

This one has really got me stumped - I have tried for about a week now using various different sites for advice all to no avail.

I am trying to load (and run) Smarty on xampp. I have followed all the advice given but when I run https://localhost/index_1.php I get the following:

Warning: require(Smarty.class.php) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\index_1.php on line 13

Fatal error: require() [function.require]: Failed opening required 'Smarty.class.php' (include_path='.;C:\xampp\php\pear";.') in C:\xampp\htdocs\index_1.php on line 13

To explain what has happened so far:

1. Loaded Smarty as follows -
c:/xampp/smarty/cache
/demo
/libs
/templates_c

2. Loaded c:/xampp/htdocs/smarty/configs
/templates

3. Having checked the PHPInfo that this is the correct file I have edited c:/xampp/php/php.ini 'paths & Directories' -
include_path = ".;C:\xampp\php\pear\";".;C:\xampp\smarty\libs\"

4. Created c:/xampp/htdocs/index_1.php with the following code -
<?php

// load Smarty library
require('Smarty.class.php');

$smarty = new Smarty;

$smarty->template_dir = 'C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = 'C:/xampp/htdocs/smarty/configs';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';

$smarty->assign('name','badBadger!');
$smarty->display('index_1.tpl');

?>

5. Created c:/xampp/htdocs/smarty/templates/index_1.tpl with the following code -
<body>
Hello, {$name}!
</body>

As I say, I have tried changing most of the parameters without any success and it is just about driving me round the bend. If anyone can see where I have gone wrong I would be very grateful.

In hope,

'H'

Re: xampp and Smarty

PostPosted: 26. June 2011 10:03
by Sharley
From a quick glance at the Smarty Documentation it wants you to put the files in the webroot folder in Windows - correct?
I think the Windows reference is related to Windows own web server IIS or now known as World Wide Publishing that uses the webroot folder - they could change the name again in the next Windows version, who knows.


Well in XAMPP the webroot is not C:\xampp but rather C:\xampp\htdocs - outside this Apache DocumentRoot folder (how it is named in Apache) then the Apache server will not be able to find the Smarty files - this is a security feature.

I hope this clue will allow you to see your issues and rectify them so you can move forward.

BTW, the readme_en.txt file tells you where to put your web site files so they can be found and parsed by Apache or sent on request to a web browser.


I just download Smarty 3.0.8 and extracted all the files in to C:\xampp\htdocs\smarty

After starting Apache I went in my browser to:
http://localhost/smarty/demo
It served the index page without errors, so I also went to:
http://localhost/smarty/demo/index_php_template.php
Again no issues there.

Re: xampp and Smarty

PostPosted: 26. June 2011 15:39
by Hamish
Sharley,

Thanks for the prompt reply but - it still doesn't work!

I'm not actually absolutely sure what you mean -

My path for index.php is - c:/xampp/htdocs/index.php

My path for Smarty.class.php is - c:/xampp/smarty/libs/smarty.class.php

My path_include in the correct php.ini file is - include_path = ".;c:\php\includes;c:\xampp\Smarty\libs\"

I have stopped and re-started Apache after each save of the .ini file.

I run 'https://localhost/test.php' with the code:
<?php
// NOTE: Smarty has a capital 'S'
require_once('Smarty.class.php');
$smarty = new Smarty();
?>
and get a blank screen - which is presumably what I should see.

I then run 'https://localhost/index_1.php' with the code:
<?php

// load Smarty library
require('Smarty.class.php');

$smarty = new Smarty;

$smarty->template_dir = 'C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = 'C:/xampp/htdocs/smarty/configs';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';

$smarty->assign('names','badBadger!');
$smarty->display('index_1.tpl');

?>

and get the following return from the browser -
Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'index_1.tpl'' in C:\xampp\smarty\libs\sysplugins\smarty_internal_template.php:163 Stack trace: #0 C:\xampp\smarty\libs\sysplugins\smarty_internal_template.php(552): Smarty_Internal_Template->isExisting(true) #1 C:\xampp\smarty\libs\Smarty.class.php(338): Smarty_Internal_Template->getRenderedTemplate() #2 C:\xampp\smarty\libs\Smarty.class.php(382): Smarty->fetch('index_1.tpl', NULL, NULL, NULL, true) #3 C:\xampp\htdocs\index_1.php(23): Smarty->display('index_1.tpl') #4 {main} thrown in C:\xampp\smarty\libs\sysplugins\smarty_internal_template.php on line 163

If you can clarify my mistake I would be very grateful .

Yours in puzzlement,

'H'