Base_url as a default value in a custom Config file |
PHP Code: namespace App\Config; Hello. I am wondering how I can access the base_url in a Config file. Doing this give me an error "Constant expression contains invalid operations" Is getting the base_url() possible as a default value in a Config file? Thanks for your time. Max
I don't know why you have this error. A workaround would be to define your config like this:
PHP Code: class MyConfig extends BaseConfig Then when you need it use base_url() like this: PHP Code: $myConfig = config('MyConfig');
You can't use dynamic value like `base_url()` in defining properties.
PHP Code: class MyConfig extends BaseConfig
@sevmusic,
>>> Is getting the base_url() possible as a default value in a Config file? Perhaps consider defining the CONST in index.php and it will be available throughout the application: file: /index.php PHP Code: # DYNAMIC PATH =================================================== file: app/Config/App.php PHP Code: public $baseURL = BASE_URL; // http://localhost:8080/';
Good suggestions here! I will also add the Registrars are a great way to add dynamic content to Config files.
|
Welcome Guest, Not a member yet? Register Sign In |