yii\db\Connection::getSlave PHP Method

getSlave() public method

If this method is called the first time, it will try to open a slave connection when [[enableSlaves]] is true.
public getSlave ( boolean $fallbackToMaster = true ) : Connection
$fallbackToMaster boolean whether to return a master connection in case there is no slave connection available.
return Connection the currently active slave connection. Null is returned if there is slave available and `$fallbackToMaster` is false.
    public function getSlave($fallbackToMaster = true)
    {
        if (!$this->enableSlaves) {
            return $fallbackToMaster ? $this : null;
        }
        if ($this->_slave === false) {
            $this->_slave = $this->openFromPool($this->slaves, $this->slaveConfig);
        }
        return $this->_slave === null && $fallbackToMaster ? $this : $this->_slave;
    }