Wouldn’t it just be doing this?
class PaginaController extends Controller
{
public function __construct()
{
// Faz alguma coisa diferente
parent::__construct();
}
}
From what 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 Controller
, but cannot lose the definitions of Controller
.
In the PHP
, parent
means you are accessing the Father 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, the other methods can be overwritten, but have to have the same signature as the original method (the same parameters). But the method __construct
does not have this restriction. So, if you want to overwrite the __construct
adding new parameters, no problems.
It is not possible to have two constructs in the same class or the classical overloading, there is another way to solve this 'problem' in php. It is possible to create classes with two constructors?
– rray
I think your question could be clearer
– Wallace Maxters