我的目录结构spl_autoload_register是类似下面PHP自动加载与子文件夹
> 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();
?>
到目前为止它是工作完美的,它呈现的温度末和填充模板增值经销商,
,但是当我在管理文件夹中打开索引文件,它提供了以下错误
Fatal error: Class 'classes\template_vars' not found in /home/aamir/www/CMS/classes/template.php on line 47
任何想法如何解决这件事情。它适用于根,而是从管理面板中它亘古不变的工作
不知何故,当我阅读它时,这段代码伤害了我。 – hakre