ZLauofBorg
New Member
Hi I'm trying to make my own simple template system kind of thingand I'm just learning about classes so I'm trying to do it with classes and objects.it works if i put this in top of every document:\[code\]$template = new Includes('name', 'path');$include = new Includes('name', 'path'); \[/code\]but it feels like it shouldn't be necessary, and its not that pretty. This is how my code is arranged right now :index.php:\[code\]<?phprequire_once 'class_include.php';$template->loadTemplate('body');\[/code\]body.php:\[code\] <?php require_once 'class_include.php'; ?> <head> <?php $template->loadTemplate('head'); ?></head><body><?php $template->loadTemplate('sidepanel'); $template->loadTemplate('content');?></body>\[/code\]class_include.php:\[code\]class Includes {public function loadTemplate($name, $path = 'template'){ require_once "$path/$name.php";}public function loadInc($name, $path = 'inc'){ require_once '$path/$name' . '.php';}}$template = new Includes('name', 'path');$include = new Includes('name', 'path'); \[/code\]error message:( ! ) Fatal error: Call to a member function loadTemplate() on a non-object in C:\wamp\www\project\template\body.php ( ! ) Notice: Undefined variable: template in C:\wamp\www\project\template\body.phpThanks for any help you can provide!