how to define a config file that i can use it any where whole project without include every where?
A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script.
If you have defined a constant, it can never be changed or undefined. To define a constant you have to use define() function and to retrieve the value of a constant, you have to simply specifying its name.
Constant vs VariablesA constant can only be defined using define() function. It cannot be defined by any simple assignment. A variable can be defined by simple assignment (=) operator. There is no need to use the dollar ($) sign before constant during the assignment.
The config. php file, located in your /global folder contains the unique settings for your Form Tools installation: your database connection settings, root folder and URLs and other information. This file is the only file in the script that should be customized.
There are two ways,
define() : The constants you define using define method is available to the whole project.
define('SITE_URL' , '/path/to/docroot/');
echo SITE_URL;
Class constant : A class constant is available to the whole project.
class MyConfig{
const SITE_URL = '/path/to/docroot/';
}
echo MyConfig::SITE_URL;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With