码迷,mamicode.com
首页 > 其他好文 > 详细

在ecshop模板使用自定义函数

时间:2015-04-20 11:08:04      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

在ecshop模板使用自定义函数

可以增加自定义函数,在模板直接调用,例如: {$userId|get_user_name} 或 {$imgUrl|set_width_height:100:200}

 

案例一(处理图片):

1.模板里使用{$imgurl|getpic:100:200}

2.includes/lib_base.php里面增加函数

 function getpic($str, $width, $height){ $len= stripos($str, ‘.‘); if($len !== false){ $str= substr($str, 0, $len).‘_‘.$width.‘-‘.$height.stristr($str, ‘.‘); return $str; } else{ return ‘/images/blank.gif‘; } }

3.includes/cls_template.php里624行

case ‘strip_tags‘: $p = ‘strip_tags(‘ . $p . ‘)‘; break;  后面增加处理函数  case ‘getpic‘: $p = ‘getpic(‘ . $p . ",$s[1],$s[2])"; break;

 

案例二(根据地区ID返回名称):

1.模板里使用{$provinceId|get_region_name}

2.includes/lib_base.php里面增加函数

function get_region_name($id){ $id = intval($id); $sql = "SELECT region_name FROM " . $GLOBALS[‘ecs‘]->table(‘region‘) . " WHERE region_id = $id"; $list = $GLOBALS[‘db‘]->getRow($sql, true); return $list[‘region_name‘]; }

3.includes/cls_template.php里624行

case ‘strip_tags‘: $p = ‘strip_tags(‘ . $p . ‘)‘; break;  //后面增加处理函数:开始 case ‘get_region_name‘: $p = ‘get_region_name(‘ . $p . ")"; break; //后面增加处理函数:结束  default: # code... break;

 

在ecshop模板使用自定义函数

标签:

原文地址:http://www.cnblogs.com/shcolo/p/4440853.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!