Andrei
Andrei

Reputation: 65

How can I pass a parameter to the parent's constructor from the main constructor?

I have these models:

class Content_model extends MY_Model{

    public function __construct()
    {
        $test='main_content';
        parent::__construct($test); 
   }
}

class MY_Model extends CI_Model {

    public function __construct($recived_parameter) {
       parent::__construct ();
        // do something with $recived_parameter
    }

}

I want to pass the argument $test to MY_Model's construct, but nothing seems to be recived. Any ideas?

Upvotes: 1

Views: 92

Answers (1)

jsdev
jsdev

Reputation: 672

smth like this might work

class Content_model extends CI_Model{

   protected $param = "Haloo";

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

class MY_Model extends Content_model {

  public function __construct() {

    echo $this->param;
  }

}

Upvotes: 1

Related Questions