windows上使用smarty模板

來源:互聯網
上載者:User
Ok I worked out the bugs. Hopefully this information will help other folks that want to install Smarty on Windows. I wish I had this info when I started, the documentation is geared towards *nix and is confusing but it was a good learning experience. (Thanks to boots for making the whole 'templates' folder click in my head)Hopefully, Monte or the Smarty folks will include this info on their web or more importantly in the installation documentation in the Smarty download.John-----------------------------------------------Installing Smarty in WindowsThis document assumes that your webserver and php5 is running.Download Smarty - http://smarty.php.netInstallation - Windows, IIS/Apache, PHP5Extract files, rename Smarty.x.x.x to smarty (suggest OUTSIDE of your www root!)Example: d:\smartyRun phpinfo.php to find out your php.ini locationEdit php.ini's include_path and add the location of the libs folder. example: include_path = ".;d:\smarty\libs" Restart IIS/ApacheSetup these two folders INSIDE your www root:(wwwroot)/smarty/templates  (this is where your templates will go)(wwwroot)/smarty/configsSetup these two folders OUTSIDE of your www root:d:/smarty/templates_cd:/smarty/cacheSetup security settings for the webserver to write to these four foldersIn (wwwroot) create index.php and in (wwwroot)/smarty/templates/index.tpl with the following code:index.php:<?php// load Smarty libraryrequire('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.phpYou can work this out to a referenced script/class:smarty_connect.php:<?php// load Smarty libraryrequire('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:<?phprequire('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! 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.