Would not it be just doing just that?
class PaginaController extends Controller
{
public function __construct()
{
// Faz alguma coisa diferente
parent::__construct();
}
}
As I understand your question, you want to have something defined in the constructor of the Controller class, but you want to add a new functionality in the constructor of a child controller of Controller
, but you can not lose the settings of Controller
.
No PHP
, parent
means that you are accessing the parent class method.
Example:
class Pato {
public function podeVoar() { return true; }
public function podeAndar() { return true; }
}
class Patinho extends Pato {
public $idade = 1;
public function podeVoar() {
if ($this->idade > 2) {
return parent::podeVoar();
}
return false;
}
}
Note : Remember that in PHP, other methods can be overwritten, but must have the same signature as the original method (the same parameters). However, the __construct
method does not have this restriction. So if you want to overwrite __construct
by adding new parameters, there are no problems.