src/Controller.php
public function changeConnectionName($connection)
    {
        if (!array_key_exists($connection, $this->connectionList)) $connection = '';

        $resolvedConnection = $this->manager->getResolvedConnectionName($connection);
        if ($resolvedConnection != $this->getConnectionName()) {
            // changed
            // save the new connection to be used as default for the user
            try {
                $this->manager->setConnectionName($resolvedConnection);
                $this->loadPersistentData();
                Cookie::queue($this->cookieName(self::COOKIE_CONNECTION_NAME), $connection, 60 * 24 * 365 * 1);
            } catch (\Exception $e) {
                Cookie::queue($this->cookieName(self::COOKIE_CONNECTION_NAME), '', 60 * 24 * 365 * 1);

                if (!$this->manager->isDefaultTranslationConnection($resolvedConnection)) {
                    // reset to default connection
                    $this->manager->setConnectionName('');
                    $this->loadPersistentData();
                } else {
                    // invalid database config or no connection
                }
            }
        } else {
            Cookie::queue($this->cookieName(self::COOKIE_CONNECTION_NAME), $connection, 60 * 24 * 365 * 1);
            if (!$this->transLocales) {
                $this->loadPersistentData();
            }
        }
    }
public function changeConnectionName($connection)
    {
        if (!array_key_exists($connection, $this->connectionList)) $connection = '';

        $resolvedConnection = $this->manager->getResolvedConnectionName($connection);
        if ($resolvedConnection != $this->getConnectionName()) {
            // changed
            // save the new connection to be used as default for the user
            try {
                $this->manager->setConnectionName($resolvedConnection);
                $this->loadPersistentData();
                Cookie::queue($this->cookieName(self::COOKIE_CONNECTION_NAME), $connection, 60 * 24 * 365 * 1);
            } catch (\Exception $e) {
                Cookie::queue($this->cookieName(self::COOKIE_CONNECTION_NAME), '', 60 * 24 * 365 * 1);

                if (!$this->manager->isDefaultTranslationConnection($resolvedConnection)) {
                    // reset to default connection
                    $this->manager->setConnectionName('');
                    $this->loadPersistentData();
                } else {
                    // invalid database config or no connection
                }
            }
        } else {
            Cookie::queue($this->cookieName(self::COOKIE_CONNECTION_NAME), $connection, 60 * 24 * 365 * 1);
            if (!$this->transLocales) {
                $this->loadPersistentData();
            }
        }
    }
public function changeConnectionName ( $ connection ) { if ( ! array_key_exists ( $ connection , $ this -> connectionList ) ) $ connection = '' ; $ resolvedConnection = $ this -> manager -> getResolvedConnectionName ( $ connection ) ; if ( $ resolvedConnection != $ this -> getConnectionName ( ) ) { // changed // save the new connection to be used as default for the user try { $ this -> manager -> setConnectionName ( $ resolvedConnection ) ; $ this -> loadPersistentData ( ) ; Cookie :: queue ( $ this -> cookieName ( self :: COOKIE_CONNECTION_NAME ) , $ connection , 60 * 24 * 365 * 1 ) ; } catch ( \ Exception $ e ) { Cookie :: queue ( $ this -> cookieName ( self :: COOKIE_CONNECTION_NAME ) , '' , 60 * 24 * 365 * 1 ) ; if ( ! $ this -> manager -> isDefaultTranslationConnection ( $ resolvedConnection ) ) { // reset to default connection $ this -> manager -> setConnectionName ( '' ) ; $ this -> loadPersistentData ( ) ; } else { // invalid database config or no connection } } } else { Cookie :: queue ( $ this -> cookieName ( self :: COOKIE_CONNECTION_NAME ) , $ connection , 60 * 24 * 365 * 1 ) ; if ( ! $ this -> transLocales ) { $ this -> loadPersistentData ( ) ; } } }
Change default connection used for this login/session and reload
persistent data if it the connection is different from what was before

@param $connection string    connection name to change to
Change default connection used for this login / session and reload persistent data if it the connection is different from what was before