Kohana_Model_Database
extends Model
extends Kohana_Model
Database Model base class.
Properties
-
protected $_db
-
Default value:
NULL
Methods
public __construct([ mixed $db = NULL ] ) (defined in Kohana_Model_Database)
Loads the database.
$model = new Foo_Model($db);
Parameters
- mixed $db = NULL - Database instance object or string
Return Values
- void
Source Code
public function __construct($db = NULL)
{
if ($db)
{
// Set the instance or name
$this->_db = $db;
}
elseif ( ! $this->_db)
{
// Use the default name
$this->_db = Database::$default;
}
if (is_string($this->_db))
{
// Load the database
$this->_db = Database::instance($this->_db);
}
}
public static factory(string $name [, mixed $db = NULL ] ) (defined in Kohana_Model_Database)
Create a new model instance. A Database instance or configuration group name can be passed to the model. If no database is defined, the "default" database group will be used.
$model = Model::factory($name);
Parameters
- string $name required - Model name
- mixed $db = NULL - Database instance object or string
Return Values
- Model
Source Code
public static function factory($name, $db = NULL)
{
// Add the model prefix
$class = 'Model_'.$name;
return new $class($db);
}