Imtehbegginer Posted July 16, 2009 Share Posted July 16, 2009 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 https://forums.phpfreaks.com/topic/166137-solved-how-to-make-something-global/ Share on other sites More sharing options...
genericnumber1 Posted July 16, 2009 Share Posted July 16, 2009 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 Link to comment https://forums.phpfreaks.com/topic/166137-solved-how-to-make-something-global/#findComment-876175 Share on other sites More sharing options...
Imtehbegginer Posted July 16, 2009 Author Share Posted July 16, 2009 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 https://forums.phpfreaks.com/topic/166137-solved-how-to-make-something-global/#findComment-876186 Share on other sites More sharing options...
Imtehbegginer Posted July 16, 2009 Author Share Posted July 16, 2009 Anyone know what to do? Link to comment https://forums.phpfreaks.com/topic/166137-solved-how-to-make-something-global/#findComment-876216 Share on other sites More sharing options...
Imtehbegginer Posted July 16, 2009 Author Share Posted July 16, 2009 Nevermind, I figured it out. Thanks genericnumber1 Link to comment https://forums.phpfreaks.com/topic/166137-solved-how-to-make-something-global/#findComment-876226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.