Changeset 2033
- Timestamp:
- 02/11/2008 11:13:50 PM (11 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/Model.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/Model.php
r1911 r2033 1 1 <?php defined('SYSPATH') or die('No direct script access.'); 2 2 /** 3 * Model class.3 * Model base class. 4 4 * 5 5 * $Id$ … … 15 15 16 16 /** 17 * Loads database to $this->db. 17 * Loads or sets the database instance. 18 * 19 * @param object Database instance 20 * @return void 18 21 */ 19 public function __construct( )22 public function __construct($database = NULL) 20 23 { 21 // Load the database into the model 22 if (Event::has_run('system.pre_controller')) 24 static $db; 25 26 if (is_object($database) AND ($database instanceof Database)) 23 27 { 24 $this->db = isset(Kohana::instance()->db) ? Kohana::instance()->db : new Database('default'); 28 // Use the passed database instance 29 $this->db = $database; 25 30 } 26 31 else 27 32 { 28 $this->db = new Database('default'); 33 // Load the default database if necessary 34 ($db === NULL) and $db = new Database('default'); 35 36 // Use the static database 37 $this->db = $db; 29 38 } 30 39 } 31 40 32 } // End Model class41 } // End Model
