//Smarty 自定义标签 register_function的运用【PHP进阶教程】 <?php require_once 'E:/smarty3/Smarty.class.php'; $smarty = new Smarty(); $smarty->template_dir = "./view/templates"; $smarty->compile_dir = "./view/templates_c"; $smarty->cache_dir = "./view/cache"; //引入文件 require_once './tags/tags.func.php'; $smarty->register_function( 'phpsoho','tags_extends' ); //这里需要注意的是,我们注册的到phpsoho句柄中的函数为tags_extends,函数名是什么意思不做一一解释,具体可以看PHP函数命名规范这样的文档。 $smarty->display('demo.html'); //tags/tags.func.php <?php function tags_extends($params) { $action = $params['action']; $optional = $params['optional']; /** * 关键词检测 */ if (! $action) { echo 'tags_extends_error', 'tags_extends action is null'; } if (! function_exists($action)) { echo 'function_exists', 'function null. class file.' . $extend_tags_file . '. classname:' . $action; } return $action($optional); } function format_data($optional) { return date("Y-m-d H:i:s"); }