Author Topic: Howto:Smarty Install with Xampp on Windows  (Read 891 times)

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Howto:Smarty Install with Xampp on Windows
« on: January 31, 2009, 11:19:34 AM »
Now I am sure if your new here, and have started the tutorials and have stumbled across xampp to design and test your page locally in windows and have trouble setting up smarty with it,with its very lack of documentation regarding a windows install.


Now I am sure you've found this document on the smarty website.
http://news.php.net/php.smarty.dev/2703
Quote
Installing Smarty in Windows

This document assumes that your webserver and php5 is running.

Download Smarty - http://smarty.php.net

Installation - Windows, IIS/Apache, PHP5
Extract files, rename Smarty.x.x.x to smarty (suggest OUTSIDE of your www root!)
Example: d:\smarty
Run phpinfo.php to find out your php.ini location
Edit php.ini's include_path and add the location of the libs folder.
example: include_path = ".;d:\smarty\libs"
Restart IIS/Apache
Setup these two folders INSIDE your www root:
(wwwroot)/smarty/templates  (this is where your templates will go)
(wwwroot)/smarty/configs

Setup these two folders OUTSIDE of your www root:
d:/smarty/templates_c
d:/smarty/cache

Setup security settings for the webserver to write to these four folders

In (wwwroot) create index.php and in (wwwroot)/smarty/templates/index.tpl with the following code:

index.php:
<?php

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

$smarty = new Smarty;

$smarty->template_dir = 'd:/inetpub/wwwroot/smarty/templates';
$smarty->config_dir = ' d:/inetpub/wwwroot/smarty/config';
$smarty->cache_dir = 'd:/smarty/smarty_cache';
$smarty->compile_dir = 'd:/smarty/smarty_templates_c';

$smarty->assign('name','fish boy!');

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

index.tpl
<html>
<body>
Hello, {$name}!
</body>
</html>

Now open index.php in your web browser (requested from your webserver)

http://webserver/index.php

You can work this out to a referenced script/class:
smarty_connect.php:
<?php

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

class smarty_connect extends Smarty
{
   function smarty_connect()
   {
        // Class Constructor.
        // These automatically get set with each new instance.

      $this->Smarty();

      $this->template_dir = ' d:/inetpub/wwwroot/smarty/templates';
      $this->config_dir = ' d:/inetpub/wwwroot/smarty/config';
      $this->compile_dir = 'd:/smarty/templates_c';
      $this->cache_dir = 'd:/smarty/cache';

      $this->assign('app_name', 'Intranet');
   }
}
?>

index.php:
<?php

require('smarty_connect.php');

$smarty = new smarty_connect;

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

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

index.tpl:
<html>
<body>
 Hello, {$name}!
</body>
</html>


If you are getting an error that Smarty.class.php isn't found chances are that your include_path isn't correct or you didn't edit the one that the webserver is using, check your phpinfo.php!

Now if your like me, that did not help me at all,just the same basic wrong locations all over the place.So in determenation to test my game locally instead of on a live server(which i had been doing till this point). I googled some more and found this which works like a charm.Just a note this if you installed xampp directly to the C:/ directory and not in Program Files etc, so simply alter the locations to where you have xampp installed.

http://www.pramodparajuli.com/tutorials/misc/smartyConfig.pdf
Quote
Configuration Tutorial
Pramod Parajuli, MMVII
CONFIGURING SMARTY TEMPLATES
1. Extract the zip file download from website ‘http://www.smarty.net/’.
2. Rename the folder ‘Smarty-2.6.19’ into ‘smarty’.
3. Copy the folder into ‘C:\Program Files\xampp\php\’ directory.
4. Create another folder ‘smarty’ in ‘C:\Program Files\xampp\htdocs\’ folder.
5. Create ‘config’ and ‘templates’ folders in the ‘C:\Program
Files\xampp\htdocs\smarty\’ folder.
6. Edit with notepad the ‘php.ini’ file in ‘C:\Program Files\xampp\apache\bin’ folder.
7. Find ‘include_path’ entry in the file and append following;
include_path = ".;C:\xampp\php\smarty\libs\"
8. Restart the Apache server.
CREATING THE CONTENTS
9. Create a template file – ‘default.tpl’. This file can be created using any web-designing
software like MS FrontPage, DreamWeaver etc.
Code: [Select]
<html>
<head>
<title>This is the static content</title>
</head>
<body>
<p><font face="Eras Light ITC" size="7" color="#008000">This is the static
content.</font></p>
<p>Now it is the dynamic content from smarty template.</p>
<p><img border="0" src="personalBanner.jpg" width="780" height="100"></p>
<p>My name: {$name}</p>
<p>My address: {$address}</p>
<p>My profession: {$profession}</p>
<p>Thank you.</p>
<p>&nbsp;</p>
</body>
2 PPj
</html>
10. Save the ‘default.tpl’ file inside ‘C:\Program
Files\xampp\htdocs\smarty\templates’ folder.
11. Create the php file ‘default.php’;
Code: [Select]
<?php
include('Smarty.class.php');
// create object
$smarty = new Smarty;
$smarty->template_dir 'C:\xampp\htdocs\smarty\templates';
$smarty->config_dir 'C:\xampp\htdocs\smarty\config';
$smarty->cache_dir 'C:\xampp\php\smarty\cache';
$smarty->compile_dir 'C\xampp\php\smarty\templates_c';
// assign some content. This would typically come from
// a database or other source, but we'll use static
// values for the purpose of this example.
$smarty->assign('name''Pramod Parajuli');
$smarty->assign('address''Kalanki, Kathmandu, Nepal');
$smarty->assign('profession''Technocrat');
// display it
$smarty->display('default.tpl');
?>
12. Save the ‘default.php’ file in ‘C:\xampp\htdocs’ folder.
USING THE TEMPLATES
13. Open a web-browser and browse ‘http://localhost/default.php’ link.
14. Presto! You got it.

And tada you should be up and running.Now I realize that the tutorial code eventually requires a smarty.php.
And here is my working smarty.php code which will be located in c:/xampp/htdocs/
Code: [Select]
<?php

require('smarty/libs/Smarty.class.php');

$smarty = new Smarty();



$smarty->template_dir 'smarty/templates';

$smarty->compile_dir 'smarty/templates_c';

$smarty->cache_dir 'smarty/cache';

$smarty->config_dir 'smarty/configs';

?>
And incase of any confusion this is what your php.ini should look like
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
include_path = ".;C:\xampp\php\pear\"
include_path = ".;C:\Program Files\xampp\php\smarty\libs\"
People Like You, Are the Reason People Like Me Need Medication

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal