2012年1月16日月曜日

Smarty 連想配列

//プログラム
<?php
require_once('MySmarty.php');
require_once('DB.php');


$dbh = DB::connect('mysql://root:mysql@127.0.0.1/test');

$data = array(    "id"    =>    1,
                "shimei"=>array("ue"=>"yamada",
                                "shita"=>"taro")
              );               
$mysmarty = new MySmarty();
$mysmarty->assign('msg','hello MySmarty');
$mysmarty->assign('data',$data);
$mysmarty->display('index.tpl');
?>
//テンプレート
<h1>{$msg}</h1>
{$data.id}<br />
{$data.shimei.ue}<br />
{$data.shimei.shita}<br />

//表示

hello MySmarty

1
yamada
taro

0 件のコメント:

コメントを投稿