php smarty 语法,php之Smarty根本语法和三大变量

php之Smarty基本语法和三大变量

在Smarty模板中主要都是以变量为主,下面就是有关Smarty的三大变量以及一些普通的用法

首先在根目录下建立要用到的文件基本和上一次一样,configs是配置文件夹

21082958.png

一、从PHP中分配的变量

用$smarty->assign()

$smarty->display()

首先先编写初始化的php代码,和上一篇的 conn.inc.php 一样

assign("title","11111111"); $smarty->assign("content","2222222222"); //分配一个关联数组,用的较少 $smarty->assign(array("author"=>"何栘烽","time"=>date("Y-m-d H:i:s"))); //注册函数 $smarty->registerPlugin("function","myfun","test"); //注册插件,将test函数注册成myfun function test($args){ //args=array("size"=>7, "color"="yellow", "num"=>5, "connect"=>"3333333") //循环遍历出 $str=""; for($i=0; $i'.$args["content"].'

'; } return $str; } //数组 $smarty->assign("contacts",array("0575-1241243","[email protected]", array("243214124", "45345"))); //对象 class Person{ public $name="kefeng"; function say(){ return $this->name."hhhhhhhh"; } } $smarty->assign("p",new Person()); $smarty->display("demo.html"); //显示的模板

demo.html:

content:

content:

content:

author:

time:

time:

time:

img.gif

name}>

say()}>

二、从配置文件中读取变量

这里需要创一个 configs 文件夹,里面配置文件 test.conf

test.conf:

bodycolor=#3e3e3ebodybgcolor=yellowborder=10align=centerwidth=800bgcolor=gray[index]one=11111[list]two=22222[content]three=33333

在demo.php 中开启session

display("demo.html"); //显示的模板

注意的是:加载配置文件:

读取:

加载区域文件要用到第二个参数:

demo.html :中,这里写一些头文件,以及加载代码

....... .......

......

三、保留变量

主要有: $_GET

$_POST

$_SESSION

$_SERVER

$_ENV

相关文章

相关视频

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值