facebook twitter hatena line email

Php/Smarty/基本メモ

提供: 初心者エンジニアの簡易メモ
2015年5月20日 (水) 03:12時点における127.0.0.1 (トーク)による版 (ページの作成:「 ==ダウンロード== http://smarty.php.net/download.php ==インストール== 解凍してウェブサーバ上にコピーするだけ ==接続方法== 以下の...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

ダウンロード

http://smarty.php.net/download.php

インストール

解凍してウェブサーバ上にコピーするだけ

接続方法

以下のようにして接続します。

----index.php---------------------------------------------------
<?php
require '../Smarty-2.6.18/libs/Smarty.class.php';
$smarty = new Smarty;
?>
----------------------------------------------------------------

helloWorldを表示

用意するファイルとディレクトリ

index.php
MySmarty.class.php
templates [ディレクトリ]
   └ - index.tpl
templates_c [ディレクトリ]
----index.php---------------------------------------------------
<?php
require 'MySmarty.class.php';
$smarty = new MySmarty;
$smarty->assign("word","helloWorld");
$smarty->assign("word2","helloWorld2");
$smarty->display('index.tpl');
?>
----------------------------------------------------------------
----MySmarty.class.php------------------------------------------
<?php
  define("ROOT_DIR","../Smarty-2.6.18");
  include_once(ROOT_DIR."/libs/Smarty.class.php");
  class MySmarty extends Smarty{
    function MySmarty(){
      $this->debugging = true;
      //$this->debugging = false;
      $this->template_dir ="./templates";
      $this->compile_dir ="./templates_c";
      $this->Smarty();
    }
  }
?>
----------------------------------------------------------------
----templates-index.tpl------------------------------------------
{$word} {$word2}
<hr>
-----------------------------------------------------------------