![]() |
Base_url as a default value in a custom Config file - 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: Base_url as a default value in a custom Config file (/showthread.php?tid=80310) |
Base_url as a default value in a custom Config file - sevmusic - 10-15-2021 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 RE: Base_url as a default value in a custom Config file - includebeer - 10-16-2021 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'); RE: Base_url as a default value in a custom Config file - kenjis - 10-16-2021 You can't use dynamic value like `base_url()` in defining properties. PHP Code: class MyConfig extends BaseConfig RE: Base_url as a default value in a custom Config file - John_Betong - 10-16-2021 @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/'; RE: Base_url as a default value in a custom Config file - MGatner - 10-23-2021 Good suggestions here! I will also add the Registrars are a great way to add dynamic content to Config files. |