September 2017
Intermediate to advanced
244 pages
6h 44m
English
The router we implemented is just routing different files, such as /posts which was being served through posts.php. Our router did not specify which function of posts.php will serve that request. We were specifying this from inside posts.php, based on the URL pattern. Just to remind you, here is that conditional portion of posts.php:
if($url == '/posts' && $_SERVER['REQUEST_METHOD'] == 'GET') { $posts = getAllPosts($dbConn); echo json_encode($posts);}
Doing that isn't difficult. We can simply put such conditions in router.php and call an appropriate function in posts.php. However, if you remember our routes.php file, it was a very simple file having key value pairs. Putting that here again for your ease:
<?php$routes = [ ...
Read now
Unlock full access