Welcome Guest, Not a member yet? Register   Sign In
Help with Abstract Classes
#1

I have in controllers folder this controller:

class Observations extends MY_Controller
{
   function __construct(){
       parent::__construct();
       $this->load->model('Observation_model');

   }
}

And in models folder I have this other code in order to make an Abstract Class.

abstract class Observation_model extends CI_Model
{
    const LEAD_OBSERVATION = 0;
    const CLIENT_OBSERVATION = 1;

    protected $id_situacion;
    protected $id_user;
}

Observation_lead_model extends Observation_model
{
    public function __construct($id_situacion,$id_user){

        $this->id_situacion = $id_situacion;
        $this->id_user = $id_user;
    }
}

class Observation_client_model extends Observation_model
{
    public function __construct($id_situacion,$id_user){
        $this->id_situacion = $id_situacion;
        $this->id_user = $id_user;
    }
}

And when I call the URL of the controller, CI returns the next error:

Fatal error: Cannot instantiate abstract class Observation_model in C:\xampp\htdocs\Projects\operarme\system\core\Loader.php

¿How could I implement abstract classess in CI? I want to make factory method pattern. 

Thanks.
Reply
#2

(This post was last modified: 08-16-2016, 06:04 AM by arma7x.)

Extend abstract class and initiate extended class. FYI, CI only load MY_ suffix only. You can declare more class in single MY_model.php
Keep calm.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB