smarty配置以及变量调节器详解 - PHP教程
发布时间:2014-04-07 07:37:17 所属栏目:PHP教程 来源:站长网
导读:最近没事儿做,就研究研究smarty模版引擎,越来越觉得smarty的强大了,smarty的教程在网上好像都比较乱。 1.下载smarty,http://www.smarty.net/download 2.把
|
最近没事儿做,就研究研究smarty模版引擎,越来越觉得smarty的强大了,smarty的教程在网上好像都比较乱。
1.下载smarty,http://www.smarty.net/download 2.把下载下来的smarty改名为smarty然后复制到新建好的文件夹里 3.新建一个smarty.inc.php(也可以是别的)
<?php
require_once 'smarty/Smarty.class.php';
$smarty=new Smarty();
$smarty->template_dir='templates/';
$smarty->compile_dir='templates_c/';
$smarty->cache_dir='temp/';
$smarty->config_dir='configs/';
$smarty->caching=0; //缓存
$smarty->cache_lifetime=60;
if (!defined('SITE_URL')){
$url=$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
define('SITE_URL', $url);
}
if (!defined('__ROOT__')){
define('__ROOT__', rtrim(dirname(__FILE__),'').'');
}
//去除反斜杠
if (get_magic_quotes_gpc()){
function stripcslashes_arr($array){
is_array($array)?array_map('srtipcslashes_arr', $array):stripcslashes($array);
}
$_POST=stripcslashes_arr($_POST);
$_GET=stripcslashes_arr($_GET);
$_REQUEST=stripcslashes_arr($_REQUEST);
$_COOKIE=stripcslashes_arr($_COOKIE);
$_SESSION=stripcslashes_arr($_SESSION);
}
//时区设置
date_default_timezone_set('PRC');
//加载function
if (file_exists('common/common.php')){
require_once 'common/common.php';
}
并且手动建立相应的目录,调试的时候建议把缓存关了。 然后新建一个index.php,
<?php
require_once 'smarty.inc.php';
$title='第一个标题';
$smarty->assign('title',$title);
$people=array(
array('name'=>'张三','sex'=>'男','age'=>'20'),
array('name'=>'李四','sex'=>'男','age'=>'40'),
array('name'=>'王五','sex'=>'女','age'=>'32'),
);
$smarty->assign('people',$people);
$smarty->display('index.tpl');
(编辑:应用网_镇江站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐

