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/";
    }
}

此时函数注册成功!

最新文章

  1. jquery属性
  2. 工作中碰到的js问题(disabled表单元素不能提交到服务器)
  3. 将datagrid中数据导出到excel中 -------&lt;&lt;工作日志2014-6-6&gt;&gt;
  4. LintCode-三数之和 II
  5. android 权限管理和签名 实现静默卸载
  6. DateTime.Now的一些用法
  7. [APIO2009]抢掠计划
  8. else语句的搭配
  9. 摄像头ov2685中关于sensor id 设置的相关的寄存器地址
  10. 深度学习Tensorflow生产环境部署(下&#183;模型部署篇)
  11. jsp 修饰 Request 及Response
  12. SVN 图标不显示的解决办法
  13. git指南目录
  14. junit与spring-data-redis 版本对应成功的
  15. jquery chosen 插件多选初始化
  16. sublime 格式化XML文件
  17. understand的安装
  18. redis源码解析之内存管理
  19. Macbook小问题
  20. TabLayout实现底部导航栏(2)

热门文章

  1. log file sync
  2. FastScroll(1)ListView打开FastScroll及自定义它的样式
  3. sublime text 2 配置文件
  4. 记录遇到的IE8兼容性问题汇总
  5. ASP.NET Cache
  6. String中intern的方法
  7. Android handler Thread 修改UI Demo
  8. OK335xS LAN8710 phy driver hacking
  9. 打造自己的reset.css
  10. date 获取昨天日期