JerryJi !

Linux Apache Mysql Php jQuery

 您当前位置 : Smarty
array.php文件
<?php
require_once ("../comm/Smarty.class.php");
$smarty = new Smarty();
$smarty->template_dir = "../Tmpl";//设置模板目录
$smarty->compile_dir = '../Tmpl_c/';
$smarty->config_dir = '../configs/';
$smarty->cache_dir = '../cache/';
$smarty->caching = false;
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";

$forum = array(
array("category_id" => 1, "category_name" => "公告","topic" => array(
array("topic_id" => 1, "topic_name" => "站内公告")
)
),
array("category_id" => 2, "category_name" => "文学专区","topic" => array(
array("topic_id" => 2, "topic_name" => "好书介绍"),
array("topic_id" => 3, "topic_name" => "奇闻共赏")
)
),
array("category_id" => 3, "category_name" => "电脑专区","topic" => array(
array("topic_id" => 4, "topic_name" => "硬件周边"),
array("topic_id" => 5, "topic_name" => "论坛")
)
)
);

$smarty->assign("forum", $forum);
$smarty->display("array.tpl");
?>


array.tpl
<{section name=sec1 loop=$forum}>
<{$forum[sec1].category_name}>
<{section name=sec2 loop=$forum[sec1].topic}>
<{$forum[sec1].topic[sec2].topic_name}>
<{/section}>
<{/section}>

全文阅读>>

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传递过来多个参数的页面

我想在SMARTY模板中使用该方法,但是不想用PHP标签来实现
查过SMARTY手册有function_regiser可以实现,但是结果有问题
PHP的FUNCTION的显示:index.php?mod=mod&act=act&id=id
我这里的id用的是动态值

function Url($mod,$act,$plus){
extract($mod);  //一定要写这句
.....
}
$tpl->function_register('U',Url);

smarty下这样调用<{U mod="mod" act="act" plus="&id="}><{$xxx}>
当然这里的id值要在php中assign
后面的id值要分开单独写

全文阅读>>

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} 
{$foo*$bar}
{if ($foo+$bar%$baz*134232+10+$b+10)}...{/if}

2 GET,POST,SERVER,SESSIOM,COOKIES等页面请求变量,可以在模板中直接访问

{*显示来自URL的GET传值"page" *} 
{$smarty.get.page}
 
{*显示来自一个表单(POST )的变量"page" *}
{$smarty.post.page}
 
{*显示cookie "username"的值 *}
{$smarty.cookies.username}
 
{*显示 server 变量"SERVER_NAME" *}
{$smarty.server.SERVER_NAME}
 
{*显示系统环境(env)的变量"PATH" *}
{$smarty.env.PATH}
 
{*显示PHP session 变量"id" *}
{$smarty.session.id}
 
{*显示来自get/post/cookies/server/env 的变量"username" *}
{$smarty.request.username}

3 可以通过{$smarty.now}来访问当前的时间戳(timestamp),可以通过date_format 变量调节器来为特定的输出作处理

{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}      
{*这里用到了Smarty变量修饰符*}

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 的使用 生成静态页面

1   第 1 页,共 1 页 7 条