Creating my First PHP Framework : Day 3
The Controller Ohhh this magic piece of code , to simplify things the role of controller is knowing
which part of code to load .
The idea here is a creating a class to auto load a model and a functions to load view(template) , but...
wait we have to know witch controller to load first , don't worry the is the Magic App.php file :
Each time we load an url we have to decompose with ( URLparser function ) it into
BASE_URL/CONTROLLER/ACTION/PARAMS
in this file we take the url , extract the controller'name as array , after we require the controller
file(after checking if exist)
Lastly , we use call_user_func_array to call the URL
The framework github
which part of code to load .
The idea here is a creating a class to auto load a model and a functions to load view(template) , but...
wait we have to know witch controller to load first , don't worry the is the Magic App.php file :
Each time we load an url we have to decompose with ( URLparser function ) it into
BASE_URL/CONTROLLER/ACTION/PARAMS
in this file we take the url , extract the controller'name as array , after we require the controller
file(after checking if exist)
require_once "../app/controllers/".$this->controller.'.php'; | |
call_user_func_array( [$this->controller, $this->method], $this->params); |
The framework github
Comments
Post a Comment