Hello,
I'm creating a script, and I'm coding the templating system at the moment. The problem I'm running into, is that I am using class methods and variables (using the
__call() magic method), in a template file, which includes no classes nor defines them.. I thought that as long as the parent file initializes the classes, I could use them in an included file in the same parent file. Here is my code:
Index.php:
PHP Code:
include_once 'includes/global.php';
try {
$tpl->header();
/*if (isset($_GET['page'])) {
$tpl->index();
} elseif(isset($_GET['wallpaper'])) {
$tpl->single();
}*/
} catch (Exception $pEx) {
echo $pEx->getMessage();
}
Global.php:
PHP Code:
require_once './config.php';
function __autoload($szClassName) {
require_once strtolower($szClassName).'.class.php';
}
$user = new User;
$site = new Settings;
$tpl = new Template($site->theme_directory());
And the method I'm trying to use is
$site->site_name(); (which I know for a fact is a valid method using
__call()). The problem is, I'm getting this error:
Code:
Fatal error: Call to a member function site_name() on a non-object in C:\xampp\htdocs\PHP\WallpaperScript\templates\default\header.php on line 6
Which shows that my class isn't defined, which goes against my thought that it would work since the global.php was included in the parent file which is including the template file.
How do I get around this?