<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                <table cellspacing="0" cellpadding="0" width="100%" summary="Header navigation table" border="0"><tbody><tr><th align="middle" colspan="3">Smarty - the compiling PHP template engine</th></tr><tr><td valign="bottom" align="left" width="25%"><a accesskey="P" href="what.is.smarty.html">Prev</a></td> <td valign="bottom" align="middle" width="50%"/> <td valign="bottom" align="right" width="25%"><a accesskey="N" href="smarty.for.designers.html">Next</a></td></tr></tbody></table> # Chapter 2. Installation **第二章.****安裝** **Table of Contents**[Requirements](#)要求???[Basic Installation](#)基本安裝[Extended Setup](#)擴展設置 # Requirements 要求? Smarty requires a web server running PHP 4.0.6 or later. Smarty要求web服務器運行php4.0.6和以上版本. # Basic Installation 基本安裝 Install the Smarty library files which are in the /libs/ directory of the distribution. These are the PHP files that you SHOULD NOT edit. They are shared among all applications and they only get updated when you upgrade to a new version of Smarty. 安裝Smarty很簡單,只須將Smarty庫文件放在/libs/目錄里就行了(就是解壓了), 你可不能修改這些php文件哦。這些文件被所有應用程序共享,也只能在你升級到新版的smarty的時候得到更新。 - /usr/local/lib/Smarty-v.e.r/ for *nix machines (linux、unix類系統 ) - and c:\webroot\libs\Smarty-v.e.r\ for the windows environment.(windows環境) <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"> <a name="AEN70"> </a> <b>Example 2.1. Required Smarty library files<br/> 例 2-1.所需的Smarty庫文件</b> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><p>Smarty-v.e.r/<br/> libs/<br/> Smarty.class.php<br/> debug.tpl<br/> sysplugins/* (everything)<br/> plugins/* (everything)</p> </td> </tr></tbody></table></div></td> </tr></tbody></table> Smarty uses a PHP constant named SMARTY_DIR which is the system filepath Smarty library directory. Basically, if your application can find the *Smarty.class.php* file, you do not need to set SMARTY_DIR, Smarty will figure it out on its own. Therefore, if *Smarty.class.php* is not in your include_path, or you do not supply an absolute path to it in your application, then you must define SMARTY_DIR manually. SMARTY_DIR *must* include a trailing slash. Here is how you create an instance of Smarty in your PHP scripts: Smarty使用一個名為'[SMARTY_DIR](#)'的php常量作為它的系統庫目錄。基本上,如果你的應用程序可以找到*Smarty.class.php*文件,你不需要設置SMARTY_DIR,Smarty將會自己運作。但是,如果 *Smarty.class.php*沒有在你的include_path(php.ini里的一項設置)里,或者沒有在你的應用程序里設置它的絕對路徑的時候,你就必須手動配置SMARTY_DIR了(大多數程序都如此)SMARTY_DIR必須包含結尾斜杠(‘/’)。 這里是你在你的php腳本里創建一個smarty的應用實例的例子: <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">&lt;?php// NOTE: Smarty has a capital 'S'require_once('Smarty.class.php');$smarty = new Smarty();?&gt;</pre></td> </tr></tbody></table></div></td> </tr></tbody></table> Try running the above script. If you get an error saying the *Smarty.class.php* file could not be found, you have to do one of the following: 試著運行一下以上腳本,如果你發現"未找到*Smarty.class.php文件"*的錯誤時,你應該這樣做: **Example 2.2. Set SMARTY_DIR constant manually ****例 2-2.手動設置SMARTY_DIR常量** | ~~~ <?php// *nix style (note capital 'S')define('SMARTY_DIR', '/usr/local/lib/Smarty-v.e.r/libs/');// windows styledefine('SMARTY_DIR', 'c:/webroot/libs/Smarty-v.e.r/libs/');// hack version example that works on both *nix and windows// Smarty is assumend to be in 'includes/' dir under current scriptdefine('SMARTY_DIR',str_replace("\\","/",getcwd()).'/includes/Smarty-v.e.r/libs/')require_once(SMARTY_DIR . 'Smarty.class.php');$smarty = new Smarty();?> ~~~ | |-----| <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"><b>Example 2-3. Supply absolute path to library file<br/> 例 2-3.加入庫文件目錄的絕對路徑</b> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">&lt;?php// *nix style (note capital 'S')require_once('/usr/local/lib/Smarty-v.e.r/libs/Smarty.class.php');// windows stylerequire_once('c:/webroot/libs/Smarty-v.e.r/libs/Smarty.class.php');$smarty = new Smarty();?&gt;</pre> </td> </tr></tbody></table></div></td> </tr></tbody></table> <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"> <p> <b>Example 2-4. Add library directory to php_include path<br/> 例 2-4.在include_path加入庫文件目錄</b> </p> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">;;;;;;;;;;;;;;;;;;;;;;;;;; Paths and Directories ;;;;;;;;;;;;;;;;;;;;;;;;;;; *nix: "/path1:/path2"include_path = ".:/usr/share/php:/usr/local/lib/Smarty-v.e.r/libs/"; Windows: "\path1;\path2"include_path = ".;c:\php\includes;c:\webroot\libs\Smarty-v.e.r\libs\"</pre> </td> </tr></tbody></table></div></td> </tr></tbody></table> <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"> <p> <b><span class="SCREEN">Example 2.5. Appending the include path in a php script with ini_set()</span><br/> 例 2-5.php腳本中使用in_set()設置加載路徑</b></p> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">[http://php.net/ini-set]&lt;?php// *nixini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'/usr/local/lib/Smarty.class.php'));// windowsini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'c:/webroot/lib/Smarty.class.php'));?&gt;</pre> </td> </tr></tbody></table></div></td> </tr></tbody></table> Now that the library files are in place, it's time to setup the Smarty directories for your application. - Smarty requires four directories which are (by default) named *templates*, *templates_c*, *configs* and *cache*. - Each of these are definable by the Smarty class properties *$template_dir*, *$compile_dir*, *$config_dir*, and *$cache_dir* respectively. - It is highly recommended that you setup a separate set of these directories for each application that will use Smarty. - You can verify if your system has the correct access rights for these directories with testInstall(). 現在庫文件已經搞定,該是設置為你的應用程序配置其他有關Smarty的目錄的時候了。 - Smarty要求4個目錄,默認下命名為:*tempalates*, *templates_c*, *configs* and *cache* 。 - 每個都是可以自定義的,可以分別修改Smarty類屬性: *[$template_dir](#)*, *[$compile_dir](#)*,[*$config_dir*](#)和*[$cache_dir](#)*。 - 強烈推薦你為每個用到smarty的應用程序設置單一的目錄(如同Smarty安裝包里的demo的文件結構)! - 可以使用[testInstall()](#)函數核實你的系統是否擁有這些目錄存取權限。 For our installation example, we will be setting up the Smarty environment for a guest book application.We picked an application only for the purpose of a directory naming convention. You can use the same environment for any application, just replace guestbook/ with the name of your application. 在我們的安裝例子里,我們將為一個留言板程序配置smarty環境。我們挑選應用程序只為了實現目錄命名約定。你可以對任何程序使用相同的環境,只要"guestbook/"改成你要的名字就可以了。 **Example 2.6. What the file structure looks like 例 2-5.文件結構示例** <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><dd><td><p> /usr/local/lib/Smarty-v.e.r/libs/<br/></p><dd>Smarty.class.php<br/> debug.tpl<br/> sysplugins/*<br/> plugins/*</dd> <p><br/> /web/www.example.com/<br/></p><dd>guestbook/<br/> --templates/<br/> ----index.tpl<br/> --templates_c/<br/> --configs/<br/> --cache/<br/> --htdocs/<br/> ----index.php</dd> </td></dd> </tr></tbody></table> Be sure you know the location of your web server document root. In our example, the document root is "/web/www.mydomain.com/docs/". The Smarty directories are only accessed by the Smarty library and never accessed directly by the web browser. Therefore to avoid any security concerns, it is recommended to place these directories *outside* of the document root. You will need as least one file under your document root, and that is the script accessed by the web browser. We will call our script "index.php", and place it in a subdirectory under the document root called "/guestbook/". Smarty will need write access (windows users please ignore) to the $compile_dir and $cache_dir directories (templates_c/ and cache/), so be sure the web server user account can write to them. 確定你已經知道了你的web服務器文件根目錄。在我們的例子里,文件根目錄是:"/web/www.mydomain.com/docs/"。Smarty的4個目錄(libs下的)只可以被那些庫文件訪問,不可以被網絡上的瀏覽器訪問的目錄。因此為避免任何安全問題,要求將那4個目錄和網頁文件目錄(就是瀏覽器看的)分開來。 在你的文檔目錄下至少得有一個文件,這個文件可以被瀏覽器訪問,我們叫它 "index.php"好了,把它放到"/guestbook/"目錄下。 Smarty的$compile_dir和$cache_dir目錄(templates_c/ and cache/)需要寫權限(windows用戶請忽略),才能確保web服務器用戶帳戶可以寫入。 <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/> This is usually user “nobody” and group “nobody”. For OS X users, the default is user “www” and group “www”. If you are using Apache, you can look in your httpd.conf file to see what user and group are being used.<br/> 通常情況下,用戶和組都為“nobody”。對于蘋果OS X系統用戶,用戶和組默認為“www”。如果使用Apache服務器,可以通過查看httpd.conf文件(通常在"/usr/local/apache/conf/"目錄下)確認用戶和組。</td> </tr></table> <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"> <p> <b><span class="SCREEN">Example 2.7. Permissions and making directories writable</span><br/> 例 2-7.權限和目錄可寫設置</b> </p> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">chown nobody:nobody /web/www.example.com/guestbook/templates_c/chmod 770 /web/www.example.com/guestbook/templates_c/chown nobody:nobody /web/www.example.com/guestbook/cache/chmod 770 /web/www.example.com/guestbook/cache/</pre></td> </tr></tbody></table></div></td> </tr></tbody></table> <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td><p>Technical Note: chmod 770 will be fairly tight security, it only allows user "nobody" and group "nobody" read/write access to the directories. If you would like to open up read access to anyone (mostly for your own convenience of viewing these files), you can use 775 instead. </p> <p> chmod 770相當安全了,它只讓user "nobody" 和 group "nobody" 讀/寫 訪問。如果你要對任何人開放讀取訪問權限(大多是為了你自己查看文件),你可以使用 775。 </p></td> </tr></table> We need to create the index.tpl file that Smarty will load. This will be located in your $template_dir. 我們需要創建index.tpl文件讓smarty載入,這個文件放在$template_dir目錄里。 <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"> <p> <b>Example 2-8. Editing /web/www.mydomain.com/smarty/guestbook/templates/index.tpl<br/> 例 2-8 編輯/web/www.mydomain.com/smarty/templates/index.tpl</b> </p> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">{* Smarty *}&#13; &#13; Hello, {$name}!</pre> </td> </tr></tbody></table></div></td> </tr></tbody></table> <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 技術提示 </caption> <tr><td><p>Technical Note: {* Smarty *} is a template comment. It is not required, but it is good practice to start all your template files with this comment. It makes the file easy to recognize regardless of the file extension. For example, text editors could recognize the file and turn on special syntax highlighting. </p> <p> {* Smarty *} 是一個模板注釋。雖然并不是必須的,但是這可以很好的鍛煉你在模板文件里加入注釋的習慣。它可以使文件便于識別。例如,一些文本編輯器可以識別這個文件,并加以語法高亮顯示。 </p></td> </tr></table> Now lets edit index.php. We'll create an instance of Smarty, assign a template variable and display the index.tpl file. In our example environment, "/usr/local/lib/php/Smarty" is in our include_path. Be sure you do the same, or use absolute paths. 現在來編輯index.php。我們將創建一個Smarty的實例,指派模板變量,顯示index.tpl文件。在我們的例子的環境里,"/usr/local/lib/php/Smarty"已經包括在了 include_path里了。 <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"> <p> <b>Example 2-9. Editing /web/www.mydomain.com/docs/guestbook/index.php<br/> 例 2-9.編輯/web/www.mydomain.com/docs/guestbook/index.php</b> </p> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">&lt;?phprequire_once(SMARTY_DIR . 'Smarty.class.php');$smarty = new Smarty();$smarty-&gt;template_dir = '/web/www.example.com/guestbook/templates/';$smarty-&gt;compile_dir = '/web/www.example.com/guestbook/templates_c/';$smarty-&gt;config_dir = '/web/www.example.com/guestbook/configs/';$smarty-&gt;cache_dir = '/web/www.example.com/guestbook/cache/';$smarty-&gt;assign('name','Ned');//** un-comment the following line to show the debug console 如果需要顯示調試控制臺,請去掉下行注釋//$smarty-&gt;debugging = true;$smarty-&gt;display('index.tpl');?&gt; &#13; </pre> </td> </tr></tbody></table></div></td> </tr></tbody></table> <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 技術提示 </caption> <tr><td><p>Technical Note: In our example, we are setting absolute paths to all of the Smarty directories. If '/web/www.mydomain.com/smarty/guestbook/' is within your PHP include_path, then these settings are not necessary. However, it is more efficient and (from experience) less error-prone to set them to absolute paths. This ensures that Smarty is getting files from the directories you intended. </p> <p> 在我們的例子里,已經設置了所有Smarty目錄的絕對目錄。如果 '/web/www.mydomain.com/smarty/guestbook/' 已經包括在 include_path里了,那么這些設置則沒有必要。但是,從經驗和通用性看來,為避免發生錯誤,還是配置一下為好。 </p></td> </tr></table> <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td><p>Note<br/> In our example, we are setting absolute paths to all of the Smarty directories. If /web/www.example.com/guestbook/ is within your PHP include_path, then these settings are not necessary. However, it is more efficient and (from experience) less error-prone to set them to absolute paths. This ensures that Smarty is getting files from the directories you intended.</p> <p>在我們的例子中,我們為所有Smarty目錄設置了絕對路徑。如果/web/www.example.com/guestbook/包含在你的php變量include_path里面,那么這樣做不是必須的。然而,設置絕對路徑會更有效率且(從經驗上說)可以減少錯誤。這樣可以確保Smarty能從你期望的目錄中取得文件!</p></td> </tr></table> Now load the index.php file from your web browser. You should see "Hello Ned, welcome to Smarty!" You have completed the basic setup for Smarty! 現在在瀏覽器打開 index.php,你應該看到"Hello Ned, welcome to Smarty!" 你現在已經完成了Smarty的基本設置,恭喜!! # Extended Setup 擴展設置 This is a continuation of the basic installation, please read that first! A slightly more flexible way to setup Smarty is to extend the class [http://php.net/ref.classobj] and initialize your Smarty environment. So instead of repeatedly setting directory paths, assigning the same vars, etc., we can do that in one place. Lets create a new directory /php/includes/guestbook/ and make a new file called setup.php.In our example environment, /php/includes is in our include_path. Be sure you set this up too, or use absolute file paths. 這是基本安裝的延續,請先閱讀上一節! 一個稍微更具靈活性的安裝方法是擴展類并初始化Smarty環境。這樣我們可以避免重復地配置路徑、設置變量...只需在一個文件里就可以搞掂Smarty安裝。 我們創建一個目錄"/php/includes/guestbook/",建立一個"setup.php"文件。下例環境中,"/php/includes"是include_path相對路徑,請先確定是否配置,或者也可以使用一個絕對路徑。 <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"><b>Example 2-10. /php/includes/guestbook/setup.php<br/></b> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">// load Smarty library&#13; require('Smarty.class.php');&#13; &#13; // The setup.php file is a good place to load&#13; // required application library files, and you setup.php文件是一個很好的加載應用程序的類庫文件&#13; // can do that right here. An example: 你也可以這樣做,例如:&#13; // require('guestbook/guestbook.lib.php');&#13; &#13; &#13; class Smarty_GuestBook extends Smarty {&#13; &#13; function Smarty_GuestBook() {&#13; &#13; // Class Constructor. These automatically get set with each new instance.&#13; //類構造函數.創建實例的時候自動配置&#13; &#13; $this-&gt;Smarty();&#13; &#13; $this-&gt;template_dir = '/web/www.mydomain.com/smarty/guestbook/templates/';&#13; $this-&gt;compile_dir = '/web/www.mydomain.com/smarty/guestbook/templates_c/';&#13; $this-&gt;config_dir = '/web/www.mydomain.com/smarty/guestbook/configs/';&#13; $this-&gt;cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/'; &#13; &#13; $this-&gt;caching = true;&#13; $this-&gt;assign('app_name','Guest Book');&#13; }&#13; &#13; }</pre> </td> </tr></tbody></table></div></td> </tr></tbody></table> Now lets alter the index.php file to use setup.php: 現在我們通過setup.php文件更改一下index.php文件 <table class="EXAMPLE" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><div class="EXAMPLE"><b>Example 2.11. /web/www.example.com/guestbook/htdocs/index.php</b> <table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td><pre class="SCREEN">&lt;?phprequire('guestbook/setup.php');$smarty = new Smarty_GuestBook();$smarty-&gt;assign('name','Ned');$smarty-&gt;display('index.tpl');?&gt;</pre> </td> </tr></tbody></table></div></td> </tr></tbody></table> Now you see it is quite simple to bring up an instance of Smarty, just use Smarty_GuestBook() which automatically initializes everything for our application. 現在你看到創建一個smarty實例有多么的簡單,只需使用Smarty_GuestBook()就可以自動初始化我們的應用程序。 <table cellspacing="0" cellpadding="0" width="100%" summary="Footer navigation table" border="0"><tbody><tr><td valign="top" align="left" width="33%"><a accesskey="P" href="what.is.smarty.html">Prev</a></td> <td valign="top" align="middle" width="34%"><a accesskey="H" href="index.html">Home</a></td> <td valign="top" align="right" width="33%"><a accesskey="N" href="smarty.for.designers.html">Next</a></td></tr><tr><td valign="top" align="left" width="33%">What is Smarty?<br/> 什么是Smarty?</td> <td valign="top" align="middle" width="34%"><a accesskey="U" href="getting.started.html">Up</a></td> <td valign="top" align="right" width="33%">Basic Installation<br/> 基本安裝</td></tr></tbody></table>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看