connection() public static method

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
return object Returns an instance of `lithium\data\Source` from the connection configuration to which this model is bound.
Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public function addAction()
 {
     $success = false;
     $errors = array();
     if (!self::$_install && $this->request->data) {
         Model::connection()->read(self::$_sql);
         if (!($success = UsersController::addUser($this->request->data['user'], $this->request->data['password'], $errors))) {
             $errors['User'] = "******";
         }
         if ($success && !($success = PostsController::addPost("Post example", self::$_lorem, $errors))) {
             $errors['Post'] = "Post can't be created.";
         }
         if ($success) {
             self::$_install = true;
         }
     }
     return compact('success', 'errors');
 }