I have stored my global constants in config->constants.php but it creating problem and throwing error I have defined it like this, how to call it in controller, code
define('SuperAdmin','1');
define('Admin','2');
define('CityAdmin' '3');
define('SupportAdmin','4');
define('RestaurantUser','5');
define('FrontUser','6');
define('Other','7');
You don't need to load constants anywhere, they're automatically autoloaded by CI itself, that is the point of them. To use them keep in mind they are constants and not a variable as you're used to with the $. So in your case after defining them, anywhere in your application you could for example use:
if($user->userType == SuperAdmin)
{
do something here;
}
Note that the SuperAdmin is written without a $ preceding it and not inside quotes. Again, after defining them in the constants file you need to do nothing else to begin using them in your application.
First of all use the conventions that you must define the constants in capital letters. Like
define('SUPERADMIN','1');
define('ADMIN','2');
define('CITYADMIN' '3');
you can use the constants in controller like
if($user->userType == SUPERADMIN)
{
//Your code ...
}
and if you want to use in html file/ view file in codeigniter you can use constants in html file like
<?php echo SUPERADMIN; ?>
You can access the constants in this way.
Always follow naming convention for constant in only capital letter. If you declared constant in application/config/constants.php file then it will available through out your application.
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