私のディレクトリ構造は以下のようなものです
> Root
> -Admin // admin area
> --index.php // admin landing page, it includes ../config.php
> -classes // all classes
> ---template.php
> ---template_vars.php // this file is used inside template.php as $template_vars = new tamplate_vars();
> -templates // all templates in different folder
> --template1
> -index.php
> -config.php
私のconfig.phpファイルで私が使用した
<?php
.... // some other php code
spl_autoload_register(NULL, FALSE);
spl_autoload_extensions('.php');
spl_autoload_register();
classes\template::setTemplate('template/template1');
classes\template::setMaster('master');
.... // some other php code
?>
適切な名前空間を設定し(クラスのみ)、ルートのindex.phpでクラスにアクセスします
<?php
require 'config.php';
$news_array = array('news1', 'news1'); // coming from database
$indexTemplate = new \classes\template('index');
$indexTemplate->news_list = $news_array; // news_list variable inside index template is magically created and is the object of template_vars class
$indexTemplate->render();
?>
これまでのところ、それは完璧に機能しており、テンプレートをレンダリングし、テンプレート vars を入力します。
しかし、管理フォルダーのインデックスファイルを開くと、次のエラーが発生します
致命的なエラー: クラス 'classes\template_vars' が /home/aamir/www/CMS/classes/template.php の 47 行目に見つかりません
このことを修正する方法はありません。root では動作しますが、管理パネル内からは動作しません