smarty3--registerPlugin()函数报错问题
smarty版本:smarty3.1.30
registerPlugin错误信息:
Notice: Trying to get property of non-object in E:\Joomla\system\libs\sysplugins\smarty_internal_templatebase.php on line 245
Fatal error: Call to a member function registerPlugin() on null in E:\Joomla\system\libs\sysplugins\smarty_internal_templatebase.php on line 245
代码示例:
system.smarty.inc.php //smarty模板配置类文件
<?php
require("libs/Smarty.class.php"); //引入smarty类库
class SmartyProject extends Smarty{
function __construct(){ //配置信息
$this->template_dir="./system/templates/";
$this->compile_dir="./system/templates_c/";
$this->config_dir="./system/configs/";
$this->cache_dir="./system/catch/";
}
}
?>
system.inc.php //类的实例化文件
<?php
require("system.smarty.inc.php");
require("system.class.inc.php");
$usefun=new UseFun();
$smarty=new SmartyProject;
function unhtml($params){
extract($params);
$text=$content;
global $usefun;
return $usefun->UnHtml($text);
}
$smarty->registerPlugin('function','unhtml','unhtml'); //注册模板函数
?>
此时会提示错误信息:
Notice: Trying to get property of non-object in E:\Joomla\system\libs\sysplugins\smarty_internal_templatebase.php on line 245
Fatal error: Call to a member function registerPlugin() on null in E:\Joomla\system\libs\sysplugins\smarty_internal_templatebase.php on line 245
解决办法:在smarty配置类文件中,引入父类的构造方法。即将system.smarty.inc.php文件改为:
require("libs/Smarty.class.php");
class SmartyProject extends Smarty{
function __construct(){
parent::__construct(); //引入父类的构造方法
$this->template_dir="./system/templates/";
$this->compile_dir="./system/templates_c/";
$this->config_dir="./system/configs/";
$this->cache_dir="./system/catch/";
}
}
此时函数注册成功!
最新文章
- jquery属性
- 工作中碰到的js问题(disabled表单元素不能提交到服务器)
- 将datagrid中数据导出到excel中 -------<;<;工作日志2014-6-6>;>;
- LintCode-三数之和 II
- android 权限管理和签名 实现静默卸载
- DateTime.Now的一些用法
- [APIO2009]抢掠计划
- else语句的搭配
- 摄像头ov2685中关于sensor id 设置的相关的寄存器地址
- 深度学习Tensorflow生产环境部署(下&#183;模型部署篇)
- jsp 修饰 Request 及Response
- SVN 图标不显示的解决办法
- git指南目录
- junit与spring-data-redis 版本对应成功的
- jquery chosen 插件多选初始化
- sublime 格式化XML文件
- understand的安装
- redis源码解析之内存管理
- Macbook小问题
- TabLayout实现底部导航栏(2)