1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
<?php
class Seeder
{
private $CI;
protected $db;
protected $dbforge;
protected $seedPath;
public function __construct()
{
$this->CI =& get_instance();
$this->CI->load->database();
$this->CI->load->dbforge();
$this->db = $this->CI->db;
$this->dbforge = $this->CI->dbforge;
}
public function call($seeder)
{
if ($this->seedPath === null) {
$this->seedPath = APPPATH . 'database/seeds/';
}
$file = $this->seedPath . $seeder . '.php';
require_once $file;
$obj = new $seeder;
$obj->run();
}
public function setPath($path)
{
$this->seedPath = rtrim($path, '/').'/';
}
public function __get($property)
{
return $this->CI->$property;
}
}