How Symfony & Twig Revamped My Routing and Page Rendering
Adding Graphs to WebSpeedReport
Published in
6 min readOct 9, 2023
When I started writing PHP, I didn’t want to jump into Laravel straight ahead.
I preferred to write vanilla PHP. When I felt ready about the fundamentals I would use a framework. I followed the same approach with my open source project, WebSpeedReport.
That was my approach until I stubbled upon Symfony’s documentation about routing and twig templating.
It seemed like it was time for a step towards frameworks.
So I utilised Symfony’s:
- Routing for the pages and rendering the html code.
- Passing data from PHP to Javascript using TWIG templating.
Updated routes, controllers and html rendering
Fortunately, the implementation and file structure of Symfony’s routing resonated with the vanilla PHP routing.
Old routing and html rendering files:
--Core
--Router.php
--Http
--Controllers
--data
--show.php
--index.php
--views
--data
--show.view.php
--partials
--head.php
--index.view.php
--routes.php