これを拡張する子クラス内の親クラスの __construct プロパティにアクセスしようとしていますが、複数のメソッドを試してみて期待した結果が得られなかったため、これを行う方法がわかりません。
したがって、baseController とそれを拡張する indexController があり、子コントローラー内の親のプロパティに直接アクセスできるようにしたいと考えています。
$config = ['site' => 'test.com'];
class baseController {
public function __construct($config){
$this->config = $config;
}
}
class indexController extends baseController {
public function __construct(){
parent::__construct(); // doesnt seem to give any outcome
}
public static function index() {
var_dump($this->config); // need to access within this method
}
}
$app->route('/',array('indexController','index')); // the route / would call this controller and method to return a response