Welcome Guest, Not a member yet? Register   Sign In
Setting baseURL in Registrar not working
#1

Hey guys,
the registrar does not seem to work (at least for me). I followed th documentation and set it up like so:
-------------------
Code:
<?php

namespace Config;

class Registrar{

  public function __construct(){
    defined('LOCATION') || define('LOCATION', $_SERVER['CI_ENVIRONMENT']);
    }

  public static function App(): array{
     
    $conf = [];
    $conf['baseURL'] = 'http://192.168.0.1:81/'; 
    if(LOCATION == 'staging') $conf['baseURL'] = 'http://mydomain.com/';

    return $conf;

    }
  }
---------------------

I always get the error 
Fatal error: Uncaught CodeIgniter\Exceptions\ConfigException: Config\App::$baseURL "/" is not a valid URL. in ...\vendor\codeigniter4\framework\system\HTTP\SiteURI.php:201

Autodiscovery is set to true.
Its only workig if a manually set the baseURL in App.php but the URL should be set dynamically based on the environment. CI3 was way more comfortable and dynamic to set up.
Anybody knows the problem?

Thanks and kind regards,
Daniel
Reply
#2

The baseURL you will set has to be listed in the allowedHostnames array.
Reply
#3

Hey michalsn,

i think you misunderstood.
I do not want to add additional domains/subdomain, i want to extend the App config to set up one single base url based on my current environment so i don't have to mess up the original config files with custom code.
Reply
#4

Unable to reproduce your error, here is a live example.

The code for app/Config/Registrar.php
PHP Code:
<?php

namespace App\Config;

class 
Registrar
{
    public static function 
Database(): array
    {
        return [
            
'default' => [
                
'database' => 'default.db',
                
'DBDriver' => 'SQLite3',
            ],
        ];
    }

    public static function 
App(): array
    {
        return [
            
'baseURL' => match(ENVIRONMENT) {
                
'staging' => 'http://mydomain.com/',
                default => 
'http://192.168.0.1:81/',
            },
            
'indexPage' => '',
            
'appTimezone' => 'America/New_York',
        ];
    }

Reply




Theme © iAndrew 2016 - Forum software by © MyBB