Modules

abstract Model_Database
extends Kohana_Model_Database
extends Model
extends Kohana_Model

Database Model base class.

package
Kohana/Database
category
Models
author
Kohana Team
copyright
© 2008-2012 Kohana Team
license
http://kohanaframework.org/license

Class declared in MODPATH/database/classes/Model/Database.php on line 3.

Constants

  • None

Properties

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);
}