Modules

abstract Model
extends Kohana_Model

Model base class. All models should extend this class.

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

Class declared in SYSPATH/classes/model.php on line 3.

Constants

  • None

Properties

Properties

protected Database $_db

database instance

Methods

public __construct( [ mixed $db = NULL ] ) (defined in Kohana_Model)

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 database instance to use
		$this->_db = $db;
	}
	elseif ( ! $this->_db)
	{
		// Use the global database
		$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)

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