Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
.phpunit.result.cache
###< phpunit/phpunit ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> symfony/asset-mapper ###
/public/assets/
/assets/vendor/
###< symfony/asset-mapper ###

###> GitGuardian/ggshield ###
/.cache_ggshield
###< GitGuardian/ggshield ###

9 changes: 9 additions & 0 deletions config/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="homepage"
path="/"
controller="App\Controller\DefaultController::index" />
</routes>
5 changes: 0 additions & 5 deletions config/routes.yaml

This file was deleted.

15 changes: 15 additions & 0 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class DefaultController extends AbstractController
{
public function index(): Response
{
return $this->render('index.html.twig');
}
}
32 changes: 32 additions & 0 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,40 @@

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

class Kernel extends BaseKernel
{
use MicroKernelTrait;

/**
* Adds or imports routes into your application.
*
* $routes->import($this->getConfigDir().'/*.{yaml,php}');
* $routes
* ->add('admin_dashboard', '/admin')
* ->controller('App\Controller\AdminController::dashboard')
* ;
*/
private function configureRoutes(RoutingConfigurator $routes): void
{
$configDir = $this->getConfigDir();

$routes->import($configDir.'/{routes}/'.$this->environment.'/*.{php,yaml}');
$routes->import($configDir.'/{routes}/*.{php,yaml}');

if (is_file($configDir.'/routes.yaml')) {
$routes->import($configDir.'/routes.yaml');
} else {
$routes->import($configDir.'/{routes}.php');
}

if (false !== ($fileName = (new \ReflectionObject($this))->getFileName())) {
$routes->import($fileName, 'attribute');
}

if (is_file($configDir.'/routes.xml')) {
$routes->import($configDir.'/routes.xml');
}
}
}
20 changes: 20 additions & 0 deletions templates/default/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'base.html.twig' %}

{% block title %}Hello DefaultController!{% endblock %}

{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>

<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>

This friendly message is coming from:
<ul>
<li>Your controller at <code>/home/mirko/code/symfony-first-app/src/Controller/DefaultController.php</code></li>
<li>Your template at <code>/home/mirko/code/symfony-first-app/templates/default/index.html.twig</code></li>
</ul>
</div>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Benvenuto in Symfony!</title>
</head>
<body>
<h1>
Benvenuto in Symfony!
</h1>
</body>
</html>