I have a model class ModelHome that is a child of Model ie:
class ModelHome extends Model
Model is a variable of the Controller class ie:
class Controller {
public $model;
public function __construct () {
$this->model = new Model;
}
}
Is it possible to access a method within the Controller class from within a method inside the ModelHome class?
I’ve tried parent:: and calling the class by name ie Controller::method but I can’t seem to find the right scope to access the method I need.
Thanks.
-Vince
First of all, you must have an instance of
ModelHome. If you make an instance ofModel, that has not automatically been extended byModelHomejust becauseModelHomeexists. So, i guess yourController::__construct()should be:However, your
ModelHomedoes not know about yourControllerclass/instance. You could make a__constructinModelHomethat takes a parameter with a link to the controller. Like this:Now, your ModelHome knows about the controller by using
$this->controller