0

Im Building an MVC Structure Application in Php. Ive Created A Config Class that calls a config file with settings in an array so that I can choose what to set in an OOP way

example - config_arrays.php in ./root/application/config

//Set System Url
$systemURL['devUrl'] = "http://localhost/Rush/";
$systemURL['liveUrl'] = 'http://www.relution-homes.com/';

example - config-class.php in ./root/system/core/

function SetBaseUrl($systemURL) {
    if (Rf_Environment == 'Development') {
        define('Rf_URL', $systemURL['devUrl']);
    } elseif (Rf_Environment == 'Production') {
        define('Rf_URL', $systemURL['liveUrl']);
    } else {
        die('Please Set Application Environment in the Applications Root index File');
    }
}

Usage - to call the class takes place in the bootstrap folder I use spl_autoload_register after calling in the config_arrays then do this

// Create a new Instance of the Config Class
$Config = new Config();
// Set The Base Url
$Config->SetBaseUrl($systemURL);

And then heres where the fun starts . . .i use

 <?php echo Rf_Url; ?>

in a page and it works fine try using it in a menu

<li><a href="<?php echo Rf_Url;?>index">Home</a></li>

And I get 'USE OF UNDEFINED CONSTANT Rf_Url - Assumed Rf_URL

I have looked at

What does the PHP error message "Notice: Use of undefined constant" mean?

And

"Use of undefined constant" notice, but the constant should be defined

With No definite answers . . .I've tried Double Quoting Everything Single Quoting Did think I could use isset() but then realized that this may not be beneficial in the long run.

Community
  • 1
  • 1
Jason Demitri
  • 63
  • 1
  • 14
  • Is your `config-class.php` included/required in the page you are trying to access this constant? – Debreczeni András Jun 13 '14 at 09:58
  • No I use spl autoload register before any of the above happens it searches for the class based on the name and automatically calls it when required ie when i use $config = new config(); it calls the class – Jason Demitri Jun 13 '14 at 10:11
  • PHP is lettercase dependant for constants. You example php does: define('Rf_URL',... your echo does: echo Rf_Url; and the warning: Assumed Rf_URL... makes sense in that it found a constant with a similar name and used it. – Ryan Vincent Jun 13 '14 at 10:58

0 Answers0