Routes


What is the function of the route? Its function to handle our request in URL then direct the application to call the page / resouce certain. In the routing we will recognize the GET and POST, the usual Harmony GET used to display the resource can be Function or Controller. While POST on Harmony is usually used to direct the form when submitted. Harmony Routes

To handle requests from users or define anything that can be accessed from the URL of the website you can open routes/web.php file.

<?php

$app->get('/', function($request, $response){
	
    return $this->view->render($response, 'welcome.twig');

});

By default Harmony already makes routes to manually display the Welcome Page (without controller) which routes routes the user to the Welcome Page when the URL is in / root.

When you need a Controllers to handle request and provide a response the routes needs to be modified. In the previous section in Controllers explanation we have made a Controllers named HomeController, well now we will call HomeContrller:index on Routes.

<?php

$app->get('/', 'HomeController:index');

The routing will direct the user to the Welcome Page when the URL is rooted.


Previous Next
Betta Dev Indonesia .Ltd - © All Right Reserved 2019