Jump to content

[SOLVED] How to make something global?


Imtehbegginer

Recommended Posts

I have a system.php file with a class called wowcms.

In wowcms there is a function called show_error($error);

 

So on my index.php page I include it and do

$wowcms = new wowcms;

 

I also have a template function that includes the header.tpl, index.tpl, and footer.tpl.

 

But when I do a $wowcms->show_error('blahblahblahblah'); nothing comes up.

 

But if I do it on index.php it works..

 

What do I do so that i can use it globally?

Link to comment
Share on other sites

Is there a problem with instantiating a new wowcms object? Did you consider making the method static? Can you pass around the wowcms object between routines? As a last resort, can the wowcms object be a singleton? (I'm not a fan of singletons, but it's still a little better than a global variable)

 

There are plenty of ways to do it other than using global variables :D

Link to comment
Share on other sites

class wowcms {
var $config;

function config() {
	@include('includes/config.php');
	$this->config = $config;
}

function load_template($theme) {
	require('templates/'.$theme.'/header.tpl');
	require('templates/'.$theme.'/index.tpl');
	require('templates/'.$theme.'/footer.tpl');
}

function show_error($text) {
	echo($text);
}

function fatal_error($text) {
	die($text);
}
}

 

There is my system.php.

 

Now on my index I use $wowcms = new wowcms;

then i require my template blah blah.

 

Now on the template I do $wowcms->show_error('whatever');

 

nothing shows up.

 

Can you show me an example of what you mean?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.