Defining extra constants CI 4 |
Hey
I am rewriting some of my smaller projects to get the hang of CI 4. But some things I am now rewriting I want to be able to reuse aftwerward without to much of a hassle. So I am trying to not meddle to much with the files allready included within CI 4 folders. One of those things I want to do is create my own little config with my own constants in there. But for the love of god I am unable to get it working. It might be something stupid but if anyone has any working example i would be gratefull. Or if you have a better way of going about it i am all ears. Just note I am in no way a experienced programmer.
@ZoeF
There must be numerous ways to achieve the task of having your own constants. The way I do it is to create a Super Class and for all your Classes to inherit the super Class: Code: <?php
Mmm yeah thats how I did it in the past. I do however believe it should not be in the controller but in a config. In that way all is a bit more structured aswell.
You can also use the Common.php file in the app folder.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(03-28-2020, 05:25 PM)ZoeF Wrote: Hey You can create a class in the Config namespace and use it just like any other class. PHP Code: <?php namespace Config; Then when you want to use "MyStuff" you create an instance of it and use the public properties like any other class. PHP Code: <?php namespace App\Controllers;
Or add it to app/Config/Constants.php.
(04-27-2024, 09:44 AM)ramonpuig Wrote:(03-30-2020, 11:21 AM)kilishan Wrote: Or add it to app/Config/Constants.php. put it like this PHP Code: defined('YOUR_CONSTANT') || define('YOUR_CONSTANT', 'youraim'); use in your controller YOUR_CONSTANT ..... Codeigniter First, Codeigniter Then You!!
yekrinaDigitals
I just checked it and it works fine with CodeIgniter 4.5.1
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |