(PHP)配置,使用Smarty技術

來源:互聯網
上載者:User

相關知識:

  1、2、模板引擎Smarty深入淺出介紹Smarty技術是PHP的精髓所在, 隨著PHP版本的逐漸提高,原來的很多方法也許太過時了,下面我就針對最新的PHP5.1.1版本的使用,配置說說如何配置。下面是一步步的來的,請注重:1、在官方下載模板庫檔案:下載了就解壓,看見一個檔案夾了,是個smarty.x.x,開啟,裡面有個libs檔案夾,ok,注重這個東西就是我們要的。2、在你的網站目錄下面,比方我的php網站IIS在物理硬碟的d:/web/web/php下面,在這個檔案夾下面建立:一個檔案夾test,然後我們把剛提到的 libs檔案夾複製道test檔案夾下面。 * 請看本文最後的注釋 Tips13、在test檔案夾下面再建立4個檔案夾:

  cache

  configs

  templates

  templates

  _c4、建立檔案text.htm:<$content>儲存在templates目錄下面。5、然後建立檔案模板設定檔: config.php

  include../libs/Smarty.class.php;$NowPathArray=explode(test,str_replace(,/,dirname(__FILE__)));

  @define(root_path, $NowPathArray[0]);

  @define(__SITE_ROOT, root_path.test);

  $tpl = new Smarty();

  $tpl->template_dir = __SITE_ROOT . /templates/;

  $tpl->compile_dir = __SITE_ROOT . /templates_c/;

  $tpl->config_dir = __SITE_ROOT . /configs/;

  $tpl->cache_dir = __SITE_ROOT . /cache/;

  $tpl->center_delimiter = <;

  $tpl->center_delimiter =>;?>儲存在主目錄也就是test下面。6、在test建立檔案test.php檔案,輸入:

  require config.php;

  $tpl->assign(title, 測試成功了,這是標題);

  $tpl->assign(content, 這是內容);

  $tpl->display(test.htm);?>7、在瀏覽器測試test.php顯示為:這是內容恭喜,配置成功.否則,失敗,再檢查是不是按照我說的來的。

  Tips1

  :為了能在網站全域使用Smarty技術,我們可以修改PHP.inc裡面的;Windows:path1;path2include_path = .;c:phpincludes改為:;Windows:path1;path2include_path=.;c:php includes;d:webwebphplibs使用模板的時候,像前面一樣的方式使用,不要:include.. /libs/Smarty.class.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.