TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 12-20-2007, 04:21 AM   #1 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default Using class methods in an included file?

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?
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:46 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design