Modules constants - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Modules constants (/showthread.php?tid=78759) |
Modules constants - ZoeF - 03-07-2021 Hey all, I am experimenting with codeigniter 4. I am intending to recreate an old project I did with CI 3. But in the process of my analysis I decided to split of all major components in seperate modules. Now as I am lazy and don't want to write specific namespace everytime. I was thinking of placing it inside the constants.php config file in every module. But I can not get it to work. Am I missing something? defined('MODULE_NAMESPACE') || define('MODULE_NAMESPACE', 'Admin'); defined('MODULE_NAMESPACE_LOC') || define('MODULE_NAMESPACE_LOC', 'Modules\Admin\\'); public function index() { return view(MODULE_NAMESPACE_LOC .'Views\admin'); } RE: Modules constants - ZoeF - 03-08-2021 After some thinkering I found a way to include the specific constants I required. I do however wonder if this is the correct approach and if there is no better way to achieve this. What I did is the following. In the app/config/Constants.php add the following: PHP Code: /** And then just create a Constants.php in your modules/Admin/Config/ Add your constants and they will be loaded if they exist. RE: Modules constants - tgix - 03-09-2021 Constants in CI has always been confusing for me. In CI3 I kept them in constants.php but in CI4 I have divided up the different sets of constants (for example DB table names and permission constants) in separate classes. I keep them in app/Libraries: PHP Code: <?php RE: Modules constants - ZoeF - 03-09-2021 Mmm I see, I do however believe constants should be in the constants file. Therefore the solution I found seems to be doing the job just fine. The thing I am wondering about is why the constants file in the modules/config folder is not beeing found automaticly. PHP Code: public $aliases = [ For one or another reason the constants are not beeing discovered. |