Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty 3.1.13, XP, Can't get index.php to work

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


Joined: 01 Mar 2013
Posts: 2

PostPosted: Fri Mar 01, 2013 8:44 pm    Post subject: Smarty 3.1.13, XP, Can't get index.php to work Reply with quote

I'm using XP SP3. I installed and extracted the Windows download (Smarty-3.1.13.zip) to the directories shown under webroot\libs:

C:\webroot
-\libs\Smarty-v.e.r\Smarty-3.1.13
--\demo
---\cache
---\configs
---\plugins
---\templates
---\templates_c
--\libs
---\plugins
---\sysplugins
-\web
--\www.example.com
---\guestbook
----\cache
----\configs
----\htdocs
----\plugins
----\templates
----\templates_c


I copied C:\webroot\libs\Smarty-v.e.r\Smarty-3.1.13\demo\ folders to C:\webroot\web\www.example.com\guestbook\
and added a new folder there htdocs\ to put index.php in as in the Basic Installation.

Then I created the following 2 files from the Basic Installation page:

index.php is in C:\webroot\web\www.example.com\guestbook\htdocs

<?php
// NOTE: The following Smarty code must be placed up front of all pages in the PHP app

define('SMARTY_DIR', 'c:/webroot/libs/Smarty-v.e.r/Smarty-3.1.13/libs/');

require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();


$smarty->setTemplateDir('/web/www.example.com/guestbook/templates/');
$smarty->setCompileDir('/web/www.example.com/guestbook/templates_c/');
$smarty->setConfigDir('/web/www.example.com/guestbook/configs/');
$smarty->setCacheDir('/web/www.example.com/guestbook/cache/');

$smarty->assign('name','Ned');

//** un-comment the following line to show the debug console
//$smarty->debugging = true;

$smarty->display('index.tpl');


?>

and index.tpl is in C:\webroot\web\www.example.com\guestbook\templates

{* Smarty *}
Hello {$name, welcome to Smarty!

When I ran it on the Smarty-supported editor Rapid PHP 2014, I got the following error:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'index.tpl''
in C:\webroot\libs\Smarty-v.e.r\Smarty-3.1.13\libs\sysplugins\smarty_internal_templatebase.php:127
Stack trace: #0 C:\webroot\libs\Smarty-v.e.r\Smarty-3.1.13\libs\sysplugins\smarty_internal_templatebase.php(374):
Smarty_Internal_TemplateBase->fetch('index.tpl', NULL, NULL, NULL, true) #1
C:\webroot\web\www.example.com\guestbook\htdocs\index.php(20):
Smarty_Internal_TemplateBase->display('index.tpl') #2 {main} thrown in
C:\webroot\libs\Smarty-v.e.r\Smarty-3.1.13\libs\sysplugins\smarty_internal_templatebase.php on line 127

On Firefox, when I entered c:\webroot\web\www.example.com\guestbook\htdocs\index.php
and ran it, this URL changed to
file:///c:/webroot/web/www.example.com/guestbook/htdocs/index.php
and gave the following error message:

setTemplateDir('/web/www.example.com/guestbook/templates/'); $smarty->setCompileDir('/web/www.example.com/guestbook/templates_c/');
$smarty->setConfigDir('/web/www.example.com/guestbook/configs/'); $smarty->setCacheDir('/web/www.example.com/guestbook/cache/');
$smarty->assign('name','Ned'); //** un-comment the following line to show the debug console //$smarty->debugging = true;
$smarty->display('index.tpl'); ?>

I realize it should show the following in both cases:

Hello Ned, welcome to Smarty!

What have I done wrong?
Thanks.


Last edited by krot on Fri Mar 01, 2013 9:02 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7237
Location: Lincoln Nebraska, USA

PostPosted: Fri Mar 01, 2013 8:51 pm    Post subject: Reply with quote

Try $smarty->testInstall()

It is probably a file permission issue. You might search the forum for windows issues, there are some common ones.
Back to top
View user's profile Send private message Visit poster's website
krot
Smarty n00b


Joined: 01 Mar 2013
Posts: 2

PostPosted: Fri Mar 01, 2013 9:26 pm    Post subject: Reply with quote

Thanks. I scanned the windows issues before, yet none seemed to hit the nail on the head.

I ran this on Rapid PHP 2014:
<?php
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();
$smarty->testInstall();
?>

and got:
Warning: require_once(SMARTY_DIRSmarty.class.php): failed to open stream: No such file or directory in C:\webroot\web\www.example.com\guestbook\htdocs\prev1~.php on line 2
Fatal error: require_once(): Failed opening required 'SMARTY_DIRSmarty.class.php' (include_path='.;C:\php\pear') in C:\webroot\web\www.example.com\guestbook\htdocs\prev1~.php on line 2

So I added the define:
<?php
define('SMARTY_DIR', 'c:/webroot/libs/Smarty-v.e.r/Smarty-3.1.13/libs/');
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();
$smarty->testInstall();
?>

and got:
Smarty Installation test...
Testing template directory...
FAILED: .\templates\ does not exist.
Testing compile directory...
FAILED: .\templates_c\ does not exist.
Testing plugins directory...
C:\webroot\libs\Smarty-v.e.r\Smarty-3.1.13\libs\plugins is OK.
Testing cache directory...
FAILED: .\cache\ does not exist.
Testing configs directory...
FAILED: .\configs\ does not exist.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete.

Why can't it find the directories?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7237
Location: Lincoln Nebraska, USA

PostPosted: Fri Mar 01, 2013 10:38 pm    Post subject: Reply with quote

you have to set them. with setTemplateDir(), etc.
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