2011-06-06 47 views
0

我使用笨,我想用我的厂库(或者,如果你知道一个更好的方法)来创建一个用户,该用户是一个扩展的抽象模型类。 和我得到的错误,我没有包括抽象类。我不知道如何将它包含在codeigniter中。 我不能只加载扩展模型的抽象类。 这是我的代码:问题,同时利用厂,抽象类和模型中的CodeIgniter

class User extends CI_Controller { 

    public function __construct() { 
     parent::__construct(); 

     $this->load->library('factory'); 

    } 

    function register(){ 
     $user = $this->factory->create('doctor'); // returns 'doctor_m' or 'patient_m' 
     $this->load->model($user); 
     $this->$user->addUser(); 
    } 
} 

abstract class User_m extends CI_Model{ 

    function __construct() { 
     parent::__construct(); 
    } 

    abstract protected function addUser(); 
    abstract protected function getUser(); 
} 

class Doctor_m extends User_m{ 

    function __construct() { 
     parent::__construct(); 
    } 

    function addUser() { 
     echo "doctor"; 
    } 

    function getUser() { 
    } 
} 

class Patient_m extends User_m{ 

    function __construct() { 
     parent::__construct(); 
    } 

    function addUser() { 
     echo 'patient'; 
    } 

    function getUser() { 
    } 
} 

class factory{ 
    function create($type){ 
     if($type == 'doctor') return 'doctor_m'; 
     else return 'patient_m'; 
    } 
} 

这是什么问题?这是在MVC中编写它的最佳方式吗?需要帮助我真的很困惑。

回答

0

如果基类是在模型中直接沿侧的其他车型,只需添加require_once('filename.php');开始的类代码之前。

如果你的基类是在库(或其他文件夹),我建议你移动它,因为我不认为一个合适的位置。如果我建立一个基本模型类,我把它放在模型目录中....

+0

我不能,user_m扩展模型,所以我不能只包括它。 – Ben 2011-06-07 09:13:21