CodeIgniter Forums
error while loading an abstract model with factory - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: error while loading an abstract model with factory (/showthread.php?tid=42395)



error while loading an abstract model with factory - El Forum - 06-06-2011

[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.


error while loading an abstract model with factory - El Forum - 06-06-2011

[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


error while loading an abstract model with factory - El Forum - 06-07-2011

[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'.