php类中引用smarty的有关问题?
php类中引用smarty的问题???
问题概述:
想在类中调用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 code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?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 code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?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 code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?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源代码,在此也贴出:
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> 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); } } }
望各位不吝指教!
------解决方案--------------------
assign需要实例化后才能引用,你的类home中有一句,parent::assign()这句其父类根本没有实例化

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











이번 장에서는 CakePHP의 환경 변수, 일반 구성, 데이터베이스 구성, 이메일 구성에 대해 알아봅니다.

PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

CakePHP는 PHP용 오픈 소스 프레임워크입니다. 이는 애플리케이션을 훨씬 쉽게 개발, 배포 및 유지 관리할 수 있도록 하기 위한 것입니다. CakePHP는 강력하고 이해하기 쉬운 MVC와 유사한 아키텍처를 기반으로 합니다. 모델, 뷰 및 컨트롤러 gu

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는
