Modules not loading config files |
I am wondering
https://forum.codeigniter.com/thread-78802.html In the above topic I asked for the best practices for the loading of config files inside of a module? I have the module loaded in the autoload, I have the auto discovery option enabled. And I have the constants added to the Modules.php $aliases array in the main app config folder. Yet the constants are not beeing found. So I cannot use them in the application. I did find a work around but that means changing the main Constants.php by adding the following code. PHP Code: /** I do however stil wonder if I missed something in the documentation. Or that is actualy a bug. (03-19-2021, 12:42 PM)ZoeF Wrote: And I have the constants added to the Modules.php $aliases array in the main app config folder. There is no aliases `constants`. Code: 'events', By the way, why do you need to use constants? You could use Config class and class constants.
There are many ways of adding constants indeed. But maybe I want the constants to be for my hole project if I add a specific module.
The most logical answer I came across is that the constants file is not a class file. That however should not be a excuse to exclude a config file from this system.
Modules do not autoload the config files in them you have to load them.
If you need constants then add them in the app/Common.php then they will be there. And here is the way I tested it. app/Common.php PHP Code: <?php What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Guess it does not work when the file is oudside of the app folder, but why would I add constants in the Common.php of the main app folder for a module that is loaded in in the Modules direcrory? Why is it so hard to add constants in a specific module? Guess I will need to use the crude solution.
directory structure >app >modules ->Admin (I want constants in here) ->Users ->... >public >vendor >...
> Why is it so hard to add constants in a specific module?
Probably because there is no way to autoload constants in PHP. I personally recommend not to use global constants at all.
Global constants could be handy for allowing hole portions of the application to either work or not work when a module is loaded or not? If a constant is present do this -> else to this. Seems like a straight forward thing. I believe their might be diffrent solutions to the idea. And I am shure I wil get an opinion from someone why this is not a good idea.
But that is beside the question.
You can always place them in your own php file and include it were needed.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Again besides the point. Why is it possible to load routes.php when it is inside a modules directory and not constants? Very strange thinking.
Autoloading constants file, as well as other non-class files, will be a new feature for the Autoloader class. This will be implemented by autoloading "files", as opposed to autoloading classes.
Are you using Composer? If yes, then there is a workaround. In your composer.json, add the files array to your autoload section. Code: "autoload": { Then in your terminal, just run ` composer dump-autoload` |
Welcome Guest, Not a member yet? Register Sign In |