PHP クラスでの Smarty の参照に関連する問題はありますか?
PHP クラスでの Smarty の参照の問題???
問題の概要:
クラスで Smarty メソッドを呼び出したいのですが、次のエラーが発生します:
PHP 致命的なエラー: そうでない場合に $this を使用しますG のオブジェクト コンテキスト内: SVNYCMSlocalhostcoresmartyssyspluginssmarty_internal_data.php 38 行目
以下のコードを投稿してください。助けていただければ幸いです [app/model/home.php は他のページを通じて _Model クラスを導入しています]:
app/model /home.php
- PHP コード
<!-- 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 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 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 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 は、参照する前にインスタンス化する必要があります。クラス ホーム、parent::assign() に、親クラスがまったくインスタンス化されていない文があります

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

ファイルのアップロードを行うには、フォーム ヘルパーを使用します。ここではファイルアップロードの例を示します。

CakePHP は、PHP 用のオープンソース フレームワークです。これは、アプリケーションの開発、展開、保守をより簡単にすることを目的としています。 CakePHP は、強力かつ理解しやすい MVC のようなアーキテクチャに基づいています。モデル、ビュー、コントローラー

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、
