I am learning PHP and trying to build my own framework on my own, I will have a front controller approach (index.php) and I was wondering if when I require my files (in my case different classes like Globals.php, BaseController.php) the construct methods of my classe will execute when required.
Index.php
<?php
//1 - Includes global variables
require_once 'config/Globals.php';
//2 - Includes Base Controller
require_once 'core/ControladorBase.php';
//Front Controller functions
require_once 'core/ControladorFrontal.func.php';
//Launch actions through controllers
if(isset($_GET["controller"])){
$controllerObj=loadController($_GET["controller"]);
launchAction($controllerObj);
}else{
$controllerObj=loadController(default_controller);
launchAction($controllerObj);
}
?>
BaseController
<?php
class BaseController{
public function __construct() {
require_once 'Connect.php';
require_once 'BaseEntity.php';
//Include all models
foreach(glob("model/*.php") as $file){
require_once $file;
}
}
//Plugins and functionalities
public function view($view,$data){
foreach ($data as $assoc_id => $value) {
${$assoc_id}=$value;
}
require_once 'core/ViewsHelper.php';
$helper=new ViewsHelper();
require_once 'view/'.$view.'View.php';
}
public function redirect($controller=default_controller,$action=default_action){
header("Location:index.php?controller=".$controller."&action=".$action);
}
//Methods for the controllers
}
?>
new BaseController.