<?php /** * smarty循环数组 */ require '../Smarty3/libs/Smarty.class.php'; require './MySmarty.php'; $smarty = new MySmarty(); $smarty->caching = true; $smarty->cache_lifetime = 3600; $liubei = array('name' => '刘备', 'age' => '28', 'wespon' => '双剑'); if (!$smarty->isCached('02.html')) { echo '11111111'; } $smarty->assign('liubei', $liubei); $zf = array('name' => '张飞', 'age' => '28', 'wespon' => '丈八蛇矛'); $smarty->assign('zf', $zf); class human { public $name = 'macao'; public $age = 29; public function say() { echo 'hello!'; } } $macao = new human(); $smarty->assign('man', $macao); $smarty->display();
<?php /** * 多重缓存页面缓存 */ require '../Smarty3/libs/Smarty.class.php'; require './MySmarty.php'; $smarty = new MySmarty(); $smarty->caching = Smarty::CACHING_LIFETIME_CURRENT; $smarty->cache_lifetime = 3600; $gid = isset($_GET['gid']) ? $_GET['gid'] + 0 : 0; if (!$smarty->isCached('03.html', $gid)) { $conn = mysql_connect('127.0.0.1', 'root', '752992807080'); mysql_query('use bool', $conn); mysql_query('set names utf8'); $sql = "SELECT goods_id,goods_name,shop_price FROM goods WHERE goods_id={$gid}"; $result = mysql_query($sql, $conn); $rs = mysql_fetch_assoc($result); $smarty->assign('goods', $rs); echo '3333'; } $smarty->display('03.html', $gid);