Welcome Guest, Not a member yet? Register   Sign In
error while loading an abstract model with factory
#1

[eluser]benb[/eluser]
i have a factory library that create the model that i need, this model is extends an abstract model.
but when i want to load it i get an error that i didn't include the abstract model class.
there is a way to solve it? how can i include it?
this is my code:
Code:
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';
    }
}


am i doing it right? like MVC model? also i want to know how can i make it works.
thanks.
#2

[eluser]InsiteFX[/eluser]
For one you cannot have a Class named factory because it is a php 5+ method!

As far as your other classes you need to include them in your main class or CI will not see them!

InsiteFX
#3

[eluser]benb[/eluser]
[quote author="InsiteFX" date="1307409203"]For one you cannot have a Class named factory because it is a php 5+ method!

As far as your other classes you need to include them in your main class or CI will not see them!

InsiteFX[/quote]

i wrote you something in the other topic. 'factory' class is only for simplicity. in my code it's 'userFactory'.




Theme © iAndrew 2016 - Forum software by © MyBB