Welcome
Welcome to Technical Editor.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features.

By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features.

Registration is fast, simple, and absolutely free, so please, join our community today!

OOoAuthors members can freely use the OOo (OpenOffice.org) category and its forums for their own use in creating, editing, or commenting on any OOoAuthors user guides.

One does NOT have to be involved with OOoAuthors for posting anything in this forum.

Smarty installation on XAMPP (Windows)

Smarty installation on XAMPP (Windows)

Postby Detroit on Sat Sep 19, 2009 4:44 pm

Smarty installation on XAMPP (Windows)

Smarty installation
  1. If XAMPP is not already installed, download the current Windows XAMPP installer from its developer's website at: http://sourceforge.net/projects/xampp/. As of September 2009, the current XAMPP version was 1.7.2.

  2. Install the XAMPP package either at its default C:\xampp location or on a different partition, such as F:\xampp. The current default Windows installation configuration should suffice, unless you want some other configuration. The current default installation is fairly automatic--just follow the instructions.

  3. Create a new folder named smarty outside the (wwwroot) folder, which is the htdocs folder when running XAMPP, but still inside the xampp folder created by the XAMPP installation (C:\xampp\smarty).

  4. Download the latest zip file version of the Smarty Template Engine at: http://www.smarty.net/download.php and extract the zip file into any convenient temporary folder.

  5. Among the extracted files and folders, there should be two folders--demo and libs, plus around ten files. Copy those two folders and the files and paste them into the smarty folder you created in step 3. [You can delete the temporary folder afterwards, as you will no longer need it.]

  6. Also create two folders--with names templates_c and cache--and place them inside the smarty folder, but outside of the (wwwroot) folder--htdocs (C:\xampp\smarty\templates_c and C:\xampp\smarty\cache).

  7. Create another folder named smarty and place it inside the htdocs folder (C:\xampp\htdocs\smarty).

  8. Create two folders--named configs and templates--inside the smarty folder created in the previous step (C:\xampp\htdocs\smarty\configs and C:\xampp\htdocs\smarty\templates). Your templates will be placed inside the templates folder.

  9. Note: The next series of steps is not necessary, but it serves as a verification that you will be modifying the correct php.ini file. Earlier versions of XAMPP (before 1.7.1) had stored their php.ini files in a different location. So, this step shows the location of the active php.ini file so that you do not inadvertently modify an older, inactive php.ini file. The steps below also test the XAMPP installation before you modify anything, in the event that if something goes wrong afterwards, you will at least know that the original XAMPP configuration was once previously OK.
    1. Start the XAMPP Control Panel Application by double-clicking xampp-control.exe in the C:\xampp folder (i.e. C:\xampp\xampp-control.exe).

    2. Click the Start button next to Apache and wait until the Start button becomes a Stop button and a green Running label appears.

    3. Click the Start button next to MySql and wait until its green Running label appears.

    4. Click the Admin button next to the Stop button for Apache. A XAMPP for Windows page, whose URL is http://localhost/xampp/ will appear in your web browser. Select the language (e.g., English) you want to use if a language page appears the first time that the XAMPP for Windows page appears.

    5. Select the Status page from the navigation menu on the left side of the web page. If everything was set up and working OK, the top eight labels should be colored green and state that they were activated.

    6. Next select the phpinfo() page from the navigation menu. The value for the active Loaded Configuration File should be C:\xampp\php\php.ini if all went well.

      You should always check the overall system whenever a change in configuration is made, so that troubleshooting and fixing any problems should be localized, and, thus, easier to correct. You can check out further other parameters in this file, as well as parameters in other XAMPP files of your setup, if you desire to explore around a bit.

  10. Inside the XAMPP installation, with a text editor open the active php.ini file whose path we just discovered. Search for the Paths and Directories section of this file, scroll down to the Windows subsection, and then edit the include library path by adding the location path of Smarty libraries. In other words, replace the line:
    include_path = ".;C:\xampp\php\PEAR" [The line's path might differ very slightly from what is represented here.]
    with the line:
    include_path = ".;C:\xampp\php\pear\;C:\xampp\smarty\libs\".

  11. Stop and restart Apache, using the Stop and Start buttons in the XAMPP Control Panel in order to set the path to Smarty.

  12. Set the security settings for the webserver to allow writing to these four folders.


Testing the Smarty setup
To test the Smarty installation, create two scripts--index.php and index.tpl. Place the index.php file into your webroot folder (htdocs, if running XAMPP) and place the index.tpl file inside of C:\xampp\htdocs\smarty\templates and copy-and-paste the following code into these two files.

index.php
Code: Select all
<?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.tpl');

?>


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

Run the index.php file in your browser, and you should see the desired output.



-----------------------------------------------
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!
Gary Schnabl
(Southwest) Detroit
Two miles NORTH! (or WEST!) of Canada--Windsor, that is...
User avatar
Detroit
Site Admin
 
Posts: 111
Joined: Wed Aug 29, 2007 3:14 pm
Location: Detroit (Michigan/US)

Return to Smarty

Who is online

Users browsing this forum: No registered users and 1 guest

cron