![]() |
2 Baseurl - 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: 2 Baseurl (/showthread.php?tid=77345) |
2 Baseurl - pippuccio76 - 08-20-2020 HI , it's possible to set base_url depends on $_SERVER variable ? RE: 2 Baseurl - jreklund - 08-22-2020 Yes, as CodeIgniter are just plain PHP you can access it everywhere. Just modify your /app/Config/App.php and you are gold. Depending on where that setting comes from, you may need to validate it first. RE: 2 Baseurl - pippuccio76 - 08-23-2020 (08-22-2020, 12:00 AM)jreklund Wrote: Yes, as CodeIgniter are just plain PHP you can access it everywhere. Just modify your /app/Config/App.php and you are gold. Depending on where that setting comes from, you may need to validate it first. But it's a variable in a class , i cannot use if statement : Code: if ($_SERVER['SERVER_NAME']== 'http://localhost:8080/') { RE: 2 Baseurl - jreklund - 08-23-2020 You can always put it in the __construct or you can modify your /public/index.php to handle all your "Environment variables" set by Apache/Nginx, and define it (just as we do with FCPATH). And use the defined name in /app/Config/App.php. With the example given, it's just better to have two different .env files, if you just need different live and development settings. RE: 2 Baseurl - pippuccio76 - 08-23-2020 Thank's work fine , can i do the same for db ? but migrate don't work because $_SERVER['SERVER_NAME'] isn't isset RE: 2 Baseurl - jreklund - 08-23-2020 Yes, I'm doing it for multiple values. Never used migrate thought, but just set a default value in case it's not set. Don't use SERVER_NAME as is, you need to add some form of validation, make an array of acceptable values for security. |