php类中引用smarty的问题???

onepointred 2011-08-27 02:05:31
问题概述:
想在类中调用smarty方法,却出现如下错误:
PHP Fatal error: Using $this when not in object context in G:\SVN\YCMS\localhost\core\smarty\sysplugins\smarty_internal_data.php on line 38
下面贴代码,希望各位能帮我下[app/model/home.php已经通过其他页面引入了_Model类]:
app/model/home.php

<?php
/**
* Name: app-model-home
* Author: yinhexi
*/
if(!defined('IN_MODEL')) die('Access Violation Error:app-model-home!');

class home extends _Model {

public static function index() {
parent::assign('title', 'YCMS');
}

}

?>

core/model/index.php

<?php
/**
* Name: core-model-index
* Author: yinhexi
*/
define('IN_MODEL', 1);
include_once(Y_CORE.DS.'config'.DS.'smarty.php'); //引入smarty类

class _Model extends Smarty {

public function __construct() {

}

//检测相关类中是否存在对应方法
protected function instance($c_f,$c_c_m) {
if(!in_array($c_f,get_class_methods($c_c_m))) {
die("Model: Class $c_c_m does not exist in Method $c_f!");
}
}

}


?>

core/config/smarty

<?php
/**
* Name: core-config-smarty
* Author: yinhexi
*/
if(!defined('IN_CORE')) die('Access Violation Error:core-config-smarty!');

include_once(Y_CORE.DS.'smarty'.DS.'Smarty.class.php');

$smarty = new Smarty();
$smarty->template_dir = Y_APP.DS.'view';//设置模版目录
$smarty->compile_dir = Y_CACHE.DS."view_c";//设置编译目录
$smarty->config_dir = Y_APP.DS.'config'.DS.'smarty';//配置目录变量
//$smarty->php_handling = SMARTY_PHP_ALLOW; //不赞成设置为SMARTY_PHP_ALLOW
$smarty->left_delimiter = "{";
$smarty->right_delimiter = "}";

//compile
#$smarty->compile_check = false;//编译检查变量

//Cache
$smarty->caching = true; //缓存模版的输出
$smarty->cache_dir = Y_CACHE; //存放模版缓存的目录名
#$smarty->cache_lifetime = 1; //缓存生命周期
?>

文件关联都没有问题,有些在这没有显示。

提示的错误所指向的是smarty源代码,在此也贴出:

public function assign($tpl_var, $value = null, $nocache = false)
{
if (is_array($tpl_var)) {
foreach ($tpl_var as $_key => $_val) {
if ($_key != '') {
$this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache);
}
}
} else {
if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache);
}
}
}


望各位不吝指教!
...全文
139 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
onepointred 2011-09-16
此问题已解决,谢谢!
  • 打赏
  • 举报
回复
张小莱 2011-09-02
parent::assign 哪来的???
  • 打赏
  • 举报
回复
Kogeo 2011-09-02
看看 学习学习。留个脚印
  • 打赏
  • 举报
回复
assign需要实例化后才能引用,你的类home中有一句,parent::assign()这句其父类根本没有实例化
  • 打赏
  • 举报
回复
相关推荐
<?php /**  * 阿里云短信验证码发送类  */ class Sms {   // 保存错误信息   public $error;   // Access Key ID   private $accessKeyId = '';   // Access Access Key Secret   private $accessKeySecret = '';   // 签名   private $signName = '';   // 模版ID   private $templateCode = '';   public function __construct($cofig = array()) {     $cofig = array (       'accessKeyId' => '***************',       'accessKeySecret' => '******************',       'signName' => '七零',       'templateCode' => 'SMS_25300059'     );     // 配置参数     $this->accessKeyId = $cofig ['accessKeyId'];     $this->accessKeySecret = $cofig ['accessKeySecret'];     $this->signName = $cofig ['signName'];     $this->templateCode = $cofig ['templateCode'];   }InvalidDayuStatus.Malformed' => '账户短信开通状态不正确',InvalidSignName.Malformed' => '短信签名不正确或签名状态不正确',InvalidTemplateCode.MalFormed' => '短信模板Code不正确或者模板状态不正确',InvalidRecNum.Malformed' => '目标手机号不正确,单次发送数量不能超过100',InvalidParamString.MalFormed' => '短信模板中变量不是json格式',InvalidParamStringTemplate.Malformed' => '短信模板中变量与模板内容不匹配'InvalidSendSms' => '触发业务流控InvalidDayu.Malformed' => '变量不能是url,可以将变量固化在模板中
Table of Contents [内容列表] Preface [序] I. Getting Started [开始] 1. What is Smarty? [什么是Smaty?] 2. Installation [安装] Requirements [安装] Basic Installation [基本安装] Extended Setup [扩展设置] II. Smarty For Template Designers [模板设计者篇] 3. Basic Syntax [基本语法] Comments [注释] Functions [函数] Attributes [属性] Embedding Vars in Double Quotes [双引号里值的嵌入] Math [数学运算] 4. Variables [变量] Variables assigned from PHP [从PHP分配的变量] Variables loaded from config files [从配置文件读取的变量] {$smarty} reserved variable [{$smarty}保留变量] 5. Variable Modifiers [变量调节器] capitalize [首字符大写] count_characters [字符计数] cat [连接字符串] count_paragraphs [计算段数] count_sentences [计算句数] count_words [计算词数] date_format [格式化日期] default [默认值] escape [编码] indent [缩进] lower [小写] nl2br [换行符替换成
] regex_replace [正则替换] replace [替换] spacify [插空] string_format [字符串格式化] strip [去除(多余空格)] strip_tags [去除html标签] truncate [截取] upper [大写] wordwrap [行宽约束] 6. Combining Modifiers [组合修改器] 7. Built-in Functions [内建函数] capture config_load foreach,foreachelse include include_php insert if,elseif,else ldelim,rdelim literal php section,sectionelse strip 8. Custom Functions [自定义函数] assign counter cycle debug eval fetch html_checkboxes html_image html_options html_radios html_select_date html_select_time html_table math mailto popup_init popup textformat 9. Config Files [配置文件] 10. Debugging Console [调试控制台] III. Smarty For Programmers [程序员篇] 11. Constants [常量] SMARTY_DIR [Smarty目录] 12. Variables [变量] $template_dir [模板目录变量] $compile_dir [编译目录变量] $config_dir [配置目录变量] $plugins_dir [插件目录变量] $debugging [调试变量] $debug_tpl [调试模板] $debugging_ctrl [调试控制变量] $global_assign [全局配置变量] $undefined [未定义变量] $autoload_filters [自动加载过滤器变量] $compile_check [编译检查变量] $force_compile [强迫编译变量] $caching [缓存变量] $cache_dir [缓存目录变量] $cache_lifetime [缓存生存时间变量] $cache_handler_func [缓存处理函数变量] $cache_modified_check [缓存修改检查变量] $config_overwrite [配置覆盖变量] $config_booleanize [配置布尔化变量] $config_read_hidden [配置读取隐藏变量] $config_fix_newlines [配置固定换行符变量] $default_template_handler_func [默认模板处理函数变量] $php_handling [php处理变量] $security [安全变量] $secure_dir [安全目录变量] $security_settings [安全配置变量] $trusted_dir [信任目录变量] $left_delimiter [左结束符变量] $right_delimiter [右结束符变量] $compiler_class [编译类变量] $request_vars_order [变量顺序变量] $request_use_auto_globals [自动全局变量] $compile_id [编译id变量] $use_sub_dirs [子目录变量] $default_modifiers [默认修正器变量] $default_resource_type [默认源类型变量] 13. Methods [方法] append [添加] append_by_ref [引用添加] assign [赋值] assign_by_ref [引用赋值] clear_all_assign [清除所有赋值] clear_all_cache [清除所有缓存] clear_assign [清除赋值] clear_cache [清除缓存] clear_compiled_tpl [清除已编译模板] clear_config [清除配置] config_load [加载配置] display [显示] fetch [取得输出的内容] get_config_vars [取配置变量的值] get_registered_object [取得已注册的对象] get_template_vars [取得模板变量的值] is_cached [是否已被缓存] load_filter [加载过滤器] register_block [注册一个块] register_compiler_function [注册编译函数] register_function [注册函数] register_modifier [注册修饰器] register_object [注册对象] register_outputfilter [注册输出过滤器] register_postfilter [注册提交过滤器] register_prefilter [注册预过滤器] register_resource [注册资源] trigger_error [触发错误] template_exists [模板是否存在] unregister_block [注销一个块] unregister_compiler_function [注销编译函数] unregister_function [注销函数] unregister_modifier [注销修饰器] unregister_object [注销对象] unregister_outputfilter [注销输出过滤器] unregister_postfilter [注销提交过滤器] unregister_prefilter [注销预过滤器] unregister_resource [注销资源] 14. Caching [缓存] Setting Up Caching [建立缓存] Multiple Caches Per Page [每页多个缓存] Cache Groups [缓存集合] Controlling Cacheability of Plugins' Output [控制插件输出的缓冲能力] 15. Advanced Features [高级特点] Objects [对象] Prefilters [预过滤器] Postfilters [后过滤器] Output Filters [输出滤镜] Cache Handler Function [缓冲处理函数] Resources [资源] 16. Extending Smarty With Plugins [以插件扩展Smarty] How Plugins Work [插件如何工作] Naming Conventions [命名约定] Writing Plugins [编写插件] Template Functions [模板函数] Modifiers [修正器] Block Functions [块函数] Compiler Functions [编译函数] Prefilters/Postfilters [预滤器/后滤器] Output Filters [输出过滤器] Resources [资源] Inserts [插入] IV. Appendixes [附录] 17. Troubleshooting [疑难解答] Smarty/PHP errors [Smarty/PHP 错误] 18. Tips & Tricks [使用技巧和经验] Blank Variable Handling [空白变量处理] Default Variable Handling [默认变量处理] Passing variable title to header template [传递变量标题给头模板] Dates [日期] WAP/WML Componentized Templates [组合的模板] Obfuscating E-mail Addresses [拒绝电子邮件地址] 19. Resources [相关资源] 20. BUGS [漏洞] 21. LIST 翻译人员列表
发帖
Framework

4247

社区成员

国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
帖子事件
创建了帖子
2011-08-27 02:05
社区公告
暂无公告