Main page

The main concept of Archict is the Brick. The project itself is a Brick and comes with a first class named Application. This class is loaded by Archict and has only one role: create the 2 routes we seen previously (see more in Routing). The one which interest us now is the first one create with this line:

$collector->addRoute(Method::GET, '', new HomeController($this->twig));

It tells to Archict that we want to listen empty path on GET method and use an instance of HomeController as the handler. So now let's see this famous handler.

First thing to notice is that the class implements interface RequestHandler. This interface is provided by the Brick Archict/Router and is mandatory to create a handler. It just needs one method: public function handle(ServerRequestInterface $request): ResponseInterface|string. In our case we simply returns a string generated by Twig rendering.

Let's just simplify it with what we need:

public function handle(ServerRequestInterface $request): string
{
    return $this->twig->render('home.html.twig');
}

And now let go see this template file and also fill it with what we need:

<!DOCTYPE html>
<html>
<head>
    <title>My super blog!</title>
</head>
<body>
    <h1>My super blog!</h1>
    <p>Welcome to the best blog of the galaxy</p>
</body>
</html>

note

I'm very bad on front-end development and design, if anyone can help me provide a better html and css example for this tutorial, please open a PR 🙏

If you go back to your browser and refresh, you can now see your brand new homepage. Feel free to tune it to your convenience.