|
发表于 2010-3-5 18:27:50
|
显示全部楼层
源链接:http://codeigniter.com/wiki/Use_URL_helper_from_Smarty/
下面的代码是我自己写的,我测试了你需要的功能,这个可以实现,如果有问题就发邮件(huboo82 [at] gmail [dot] com)告诉我吧。
参数url可以是字符串,也可以是数组(array('news', 'local', '123'))。
PHP复制代码
<?php
/**
* @filesource http://codeigniter.com/wiki/Use_URL_helper_from_Smarty/
* @author Modified by huboo <huboo82@gmail.com>
* @link http://huboo.eblhost.cn/
* @usage {site_url url="controller/function/"(Optional: dyn=$parameter)}
* @example
* //result: http://localhost/user/profile/1
* {site_url url="user/profile/" dyn=$slide.uid}
*
* //$uri_seg = array(date('Y/n/j', $create_date), $url_topic)
* //result: http://localhost/2010/2/26/passing-afternoon
* {site_url url=$uri_seg}
* or
* {site_url url=$createdate|date_format:"%Y/%m/%d/" dyn=$url_topic}
*/
function smarty_function_site_url ($params, &$smarty)
{
//check if the needed function exists
//otherwise try to load it
if(!function_exists('site_url'))
{
//return error message in case we can't get CI instance
if (!function_exists('get_instance')) return "Can't get CI instance";
$CI= &get_instance ();
$CI->load->helper('url');
}
$url = (isset($params['url']) ? $params['url'] : False);
$var = (isset($params['dyn']) ? $params['dyn'] : '');
if($url)
return (is_array($url)) ? site_url (array_merge($url, array($var))) : site_url ($url . $var);
else
return base_url ();
}
?>
复制代码 |
|