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)


require_once "../app/controllers/".$this->controller.'.php';

Lastly , we use call_user_func_array to call the URL


call_user_func_array( [$this->controller, $this->method], $this->params);


The framework github

Comments

Popular posts from this blog

Twitter API with PHP

Realtime Chat Application with CakePHP and Socket.IO #1

Let's build a mobile application with Ionic Framework #3