How to install smarty in Windows

Source: Internet
Author: User

 


I remember that I wrote a simple tutorial on installing PhP4 for Windows + IIS last year. On that day, I went to Baidu and found several pages. This article was reposted by many websites and blogs, the number of times I read on the Forum has reached more than 1800 incredible times today. We can see that you are welcome to the following articles. Recently I plan to start researching a template that I didn't like very much before. I found smarty, but I didn't find a good installation article in Chinese. I had to go to a foreign website and finally found a smarty Development Group Article, it is easy to understand and can be easily translated. In addition, the reading habits of Chinese people are sorted out in terms and sentences, so this article is available. After my tests, I successfully installed it in Win2000 + php4.3 + IIS at one time, which is very effective. So I have compiled this article to help my friends who like the smarty template technology and have just begun.

The configuration process is divided into nine steps. The article looks long because the webmaster cannot explain each step in detail, which is very simple, it is definitely a "concise tutorial ". According to this tutorial, smarty can be successfully configured for users with an IQ greater than zero !~ _~

This article applies to: Windows system + IIS/Apache + PhP4/PhP5

Before starting this article, make sure that your web server and PHP have been configured and work properly.

1. Download the smarty package
You can download: http://smarty.php.net from official site
Users of the 17php forum can download the latest version 2.6.9 from the Forum.
Size: only 140 K compression format: .tar.gz
Forum: bbs.17php.com/download/smarty269.tar.gz

2. decompress the smarty package and find a suitable location for storage. after decompression, the folder name may be smarty. x. x. x, change it to smarty (this is only for future convenience, not required ), then copy the folder containing the smarty file to a directory (we recommend that you do not place it in your website directory, so that others can access these files through the path, if you have to put it in the website directory, the names of the best directories are somewhat uncommon. These files may not cause security issues even if they are accessed by others, but everything is done just in case ).
In the following content, we assume that your file is stored in D:/smarty.

3. Find your php. ini configuration file (you can run phpinfo () to view the path of this file, but it is usually stored in the system directory) to modify PHP. add the path of the smarty library file to the initde_path option, for example:
Include_path = ".; D:/smarty/Libs"
Note: php. ini contains two types of include_path, which are used in UNIX and windows. You need to modify the values used in Windows:
-------------------------------------------------------------
; Windows: "/path1;/path2"
Include_path = ".; C:/PhP4/shortdes; D:/smarty/Libs"
--------------------------------------------------------------
4. Restart IIS/Apache to make the modification take effect.
The restart method is simple. You can simply restart Apache directly. For IIS, you can run the net stop iiadmin command to disable IIS and run the Net start w3svc command to start IIS. If it doesn't restart, simply restart the computer.

5. Create a folder under your website directory with any name. Assume mysmarty:
Then, create two folders, templates and configs, under the mysmarty directory.
After the creation is complete:
(Your website directory)/mysmarty/templates (this directory is used to store templates)
(Your website directory)/mysmarty/configs (this directory is used to store some configuration information)

6. Create two folders under the mysmarty directory named smarty_cache and smarty_templates_c respectively. Why didn't I create them together? Because this step does not exist in the original official materials, and I found during the configuration process that without these two folders, Smarty will not work, I don't know why the official smarty version is different from the latest version. However, if you configure these two directories, smarty can work smoothly. Therefore, we recommend that you configure it.

7. At this time, you should not forget to set the permissions for the Four folders we created from the beginning to now. Of course, it also includes the permissions for storing the folder D:/smarty of smarty, because some systems in the NTFS format have strict Permission Regulations, after creating your directory, you must have sufficient permissions to allow web programs to access it. In general, systems using NTFS partition format in Win2000 and win2003 need to do this. The specific method is to right-click the folder and open the "Security" label in "properties, the list of users who can access this directory is listed. If you do not have the Web access permission, you need to add the Internet Guest Account and the IIS process account that starts. If you are in trouble, you can directly add the Everyone user group to allow access by any user.

8. The installation is basically completed at this time. You can test the first simple example:
Create the index. php file under your website directory and create the index. TPL file under (website directory)/mysmarty/templates/. Enter the following code respectively.
Index. php
<? PHP
// Load the smarty Library
Require ('smarty. Class. php ');

Secret $ smarty = new smarty;

// The following (your website directory) uses an absolute path, such as D:/intepub/wwwroot
Templates $ smarty-> template_dir = '(your website directory)/mysmarty/templates ';
Secret $ smarty-> config_dir = '(your website directory)/mysmarty/configs ';
Else $ smarty-> cache_dir = (your website directory)/mysmarty/smarty_cache ';
Export $ smarty-> compile_dir = (your website directory)/mysmarty/smarty_templates_c ';
// Required parameter configuration before using smarty for the above four actions

Repository $ smarty-> assign ('name', 'Learn to install smarty with 17php ');
Functions $ smarty-> display ('index. tpl ');
?>

Index. TPL
<HTML>
<Body>
Hello, {region $ name }!
</Body>
</Html>
9. Now you can finally watch the following masterpiece. Run index. php (of course, it runs on your web server, exactly the same as running a common PHP file .)
Http: // localhost/index. php
If the following output is displayed, the installation is successful ~~~ Is it easy?
Hello, learn to install smarty with 17php!

Note: although the smarty installation has been completed so far, the webmaster still wants to give you some small suggestions. In the example above, we can find that if we need to set parameters before using smarty every time, it is too troublesome. At this time, you can wrap the four lines of code set for the smarty information in one class or one containing file. In this way, you do not need to configure the information before each use. This is the usage knowledge of smarty, which is not covered in this article. The webmaster is still in the learning process. Wait till later to continue introducing articles related to smarty ~~~
It took two hours to translate and sort out this article. I hope it will help you a little.

 

From http://qilubbs.blog.sohu.com/107031772.html

Attached code

Index. TPL

Index. php

<?php  require('Smarty.class.php');  $smarty = new Smarty();    $smarty->template_dir='D:/apache2/htdocs/mysmarty/templates';  $smarty->config_dir='D:/apache2/htdocs/mysmarty/configs';  $smarty->cache_dir='D:/apache2/htdocs/mysmarty/smarty_cache';  $smarty->compile_dir='D:/apache2/htdocs/mysmarty/smarty_templates_c';  $smarty->assign('name','Follow me study PHP Smarty!');  $smarty->display('index.tpl');?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.