Linux Apache Mysql Php jQuery
2010-07-02 16:24:22 | 作者:jerryji | 评论:0 | 标签:smarty二维数组循环实例
This is the default value to output if the variable is empty.
这是变量为空的时候的默认输出。
注意是为空
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle|default:"no title"}
{$myTitle|default:"no title"}
输出结果:
Dealers Will Hear Car Talk at Noon.
no title
2010-01-11 10:13:25 | 作者:jerry | 评论:0 | 标签:smarty default
比如说我要缓存admin_main_mem.php?action=1&page=1,甚至更多$_GET参数的页面的时候我可以通过smarty这么做
function smartyDisplay($cache_id){
$getKey=array_keys($_GET);
if(empty($cache_id)) {
echo "j";
}
else {
if(is_array($cache_id)) {
foreach ($cache_id as $value) {
$key = array_search($value,$getKey);
if(isset($_GET[$value])){
$cache_str .= $getKey[$key].":".$_GET[$value]."-";
}
}
}
}
return $cache_str;
}
$smarty->display('admin_main_mem.html',smartyDisplay(array('action','page')));
$cache_str就会是:action:1-page:2;
这样我们就把cache_id重新进行组合了 然后剩下的就交给smarty吧
这个我在iestore商城中已经使用了,如果不会用,可以到IESTORE商城中搜smartyDisplay这个方法名就可以找到使用方法
2009-12-30 14:24:35 | 作者:jerry | 评论:3 | 标签:smarty缓存$_GET传递过来多个参数的页面
2009-12-30 09:00:38 | 作者:jerry | 评论:1 | 标签:smarty function_register smarty使用php方法
1. 在php标签中直接写php脚本
{php}
.....
{/php}
2. 在php标签中include php文件
{php}
include(相对或绝对路径);
{/php}
注意:如果是相对路径的话,该路径的根目录与调用改模板的PHP页面是一样的,而不是该模板的根目录。
2009-12-29 16:56:39 | 作者:jerry | 评论:0 | 标签:Smarty中使用php脚本
1 数学运算可以直接应用于模版标记中的变量
{$foo+1} |
2 GET,POST,SERVER,SESSIOM,COOKIES等页面请求变量,可以在模板中直接访问
{*显示来自URL的GET传值"page" *} |
3 可以通过{$smarty.now}来访问当前的时间戳(timestamp),可以通过date_format 变量调节器来为特定的输出作处理
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"} |
4 可以通过{$smarty.const}来直接访问 PHP 常量
{$smarty.const.My_Val}
2009-08-13 18:28:49 | 作者:jerry | 评论:0 | 标签:Smarty在模板文件中的一些应用
include("Smarty.class.php");
$smarty = new Smarty;
$smarty->caching = true;
// only do db calls if cache doesn't exist
// 只有在缓存不存在时才调用数据库
if(!$smarty->is_cached("index.tpl"))
{
// dummy up some data
$address = "245 N 50th";
$db_data = array(
"City" => "Lincoln",
"State" => "Nebraska",
"Zip" = > "68502"
);
$smarty->assign("Name","Fred");
$smarty->assign("Address",$address);
$smarty->assign($db_data);
}
// capture the output
// 捕获输出
$output = $smarty->fetch("index.tpl");
// do something with $output here
// 对将要输出的内容进行处理
echo $output;
2009-07-01 13:24:50 | 作者:jerry | 评论:0 | 标签:$smarty->fetch 的使用 生成静态页面