Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter set constants in custom library

I am using codeigniter for a project. I have a custom library in which there are constants in which I will use in my custom functions in the library. How do I declare such constants?

like image 931
kkh Avatar asked Nov 16 '25 21:11

kkh


1 Answers

If you are going to use that constants only in your library, you must declare it inside of your class:

<?php
class my_class {
    const MY_CONSTANT = 10;

And then call it with:

self::MY_CONSTANT

If you need that your constants are available in the rest of the application, you must declare it in your application/config/constants.php file

like image 63
m4t1t0 Avatar answered Nov 19 '25 12:11

m4t1t0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!