6. 自定义函数
来源:互联网 发布:c语言库函数大全 编辑:程序博客网 时间:2024/05/22 04:52
1.自定义函数
2.块注册方式
TestController3.php
<?phprequire_once './libs/Smarty.class.php';$smarty = new Smarty();//自定义一个函数//在 tpl 调用形式 {test1 times="4" size="5" color="red"}function test1($args){ $str = ''; for($i=0;$i<$args['times'];$i++) { $str .= "<br/><font color='" . $args['color'] . "'" . "size='" . $args['size'] . "'" . ">" . $args['con'] ."</font>"; } return $str;}function test2($args){ $str = ''; for($i=0;$i<$args['times'];$i++) { $str .= "<br/><font color='" . $args['color'] . "'" . "size='" . $args['size'] . "'" . ">" . $args['con'] ."</font>"; } return $str;}//定义一个计算函数function jisuan($args){ switch($args['operator']) { case '+': $res = $args['num1']+$args['num2']; break; case '-': $res = $args['num1']-$args['num2']; break; case '*': $res = $args['num1']*$args['num2']; break; case '/': $res = $args['num1']/$args['num2']; break; default: $res = '不正确'; break; } return $res;}$smarty->register_function('jisuan','jisuan');//注册函数$smarty->register_function('wjh','test1');//以块方式注册$smarty->register_block('wjh_block','test2');$smarty->display('test3.tpl');
test3.tpl
<h1>自定义函数</h1>{*{wjh times='5' con='hello,北京' color='blue' size='5'}*}<h2>块方式调用</h2>{wjh_block times='5' con='hello,北京' color='blue' size='5'}{/wjh_block}<h2>计算</h2>{jisuan num1='3' num2='4' operator='+'}
3.以插件形式增加一个自定义函数
以 block 方式,添加plus:同样要保证命名规范
<h2>counter 计数器 </h2>start 是除初始值 skip 表示调用一次自增长多少<br/>{<counter start=0 skip=1 print=true>}{<counter>}<bf/>{<counter>}<bf/>{<counter>}<bf/>{<counter>}<bf/>
0 0
- 6. 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数:
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 接口与抽象类
- CodeForces 266E More Queries to Array... 线段树
- mysqldump使用
- Jquery滑块展示
- 使用git和github管理自己的项目---真实开发环境的策略
- 6. 自定义函数
- JSP学习笔记五之application和page对象
- Spring MVC 通过@Value注解读取.properties配置
- oracle中pl/sql程序高级类型的使用
- 学习C++反汇编-构造函数
- 集训队专题(7)1003 Task Schedule
- 机器学习: 贝叶斯决策 2
- 对象 接口 抽象类
- hdu 1584 蜘蛛牌【dfs+简单剪枝】