I have an api application with api/common/config/main.php which gets loaded when the application runs. However, I have api/module/v1/config/main.php configuration that I want to include in the module.php init() method. I tried using \Yii::configure($this, require DIR . ‘/config/main.php’), but that overrides whatever configuration that was previously loaded. What is the best way to accomplish this?
Yes, that is how I have it working, but the downside with this approach is I am hard coding the versioning of the API config. I want the correct config for that version of the API to load depending on the url. For example "https://domain.com/api/v1/<controller>/<action>" should load the v1 config and "https://domain.com/api/v2/<controller>/<action>" should load the v2 config.
Thanks @softark, I agree! This is exactly what I tried. My url manager rules and all my major configurations all get loaded fine in my common/config/main.php. I have a few additional parameters in my api/module/v1/config/params.php and my api/module/v1/config/main.php file that are specific to v1 of my API. So I am trying to load them from my module init(). It gets loaded, but all my previous configuration from /common/config/main.php get’s overwritten with the config file from my module.
public function init()
// initialize the module with the configuration loaded from config.php
\Yii::configure($this, require __DIR__ . '/config/main.php');