lithium\data\Model::connection PHP Метод

connection() публичный статический Метод

Gets the connection object to which this model is bound. Throws exceptions if a connection isn't set, or if the connection named isn't configured.
public static connection ( ) : object
Результат object Returns an instance of `lithium\data\Source` from the connection configuration to which this model is bound.
    public static function &connection()
    {
        $self = static::_object();
        $connections = $self->_classes['connections'];
        $name = isset($self->_meta['connection']) ? $self->_meta['connection'] : null;
        if ($conn = $connections::get($name)) {
            return $conn;
        }
        $class = get_called_class();
        $msg = "The data connection `{$name}` is not configured for model `{$class}`.";
        throw new ConfigException($msg);
    }

Usage Example

Пример #1
0
 public static function &connection()
 {
     $self = static::_object();
     if ($self->_useRealConnection) {
         return parent::connection();
     }
     if (!$self->_connection) {
         $self->_connection = new MongoDb(array('autoConnect' => false));
     }
     return $self->_connection;
 }
All Usage Examples Of lithium\data\Model::connection