View #8
29
src/Controller/SpeciesController.php
Normal file
29
src/Controller/SpeciesController.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Species;
|
||||||
|
use App\Repository\SpeciesRepository;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
class SpeciesController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/species', name: 'app_species')]
|
||||||
|
public function index(SpeciesRepository $repository): Response
|
||||||
|
{
|
||||||
|
$species = $repository->findAll();
|
||||||
|
return $this->render('species/index.html.twig', [
|
||||||
|
'species' => $species,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/species/{id}', name: 'app_species_detail')]
|
||||||
|
public function detail(Species $specie): Response
|
||||||
|
{
|
||||||
|
return $this->render('species/detail.html.twig', [
|
||||||
|
'specie' => $specie,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@@ -25,7 +25,8 @@ class AppFixtures extends Fixture
|
|||||||
->setPublicationDate($date)
|
->setPublicationDate($date)
|
||||||
->setLatitude($faker->randomFloat())
|
->setLatitude($faker->randomFloat())
|
||||||
->setLongitude($faker->randomFloat())
|
->setLongitude($faker->randomFloat())
|
||||||
->setCommentary($faker->text());
|
->setCommentary($faker->text())
|
||||||
|
-> setSpecies($species);
|
||||||
$manager->persist($species);
|
$manager->persist($species);
|
||||||
$manager->persist($post);
|
$manager->persist($post);
|
||||||
}
|
}
|
||||||
|
43
templates/species/detail.html.twig
Normal file
43
templates/species/detail.html.twig
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Herbarium - Détail de l'espèces{% 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>{{ specie.vernacularName }}</h1>
|
||||||
|
<p>
|
||||||
|
🔬 Nom Scientifique : {{ specie.scientificName }}<br/>
|
||||||
|
📍 Region : {{ specie.region }}
|
||||||
|
</p>
|
||||||
|
<div>
|
||||||
|
<h2>Posts :</h2>
|
||||||
|
|
||||||
|
{% for post in specie.posts %}
|
||||||
|
<div>
|
||||||
|
<dt>
|
||||||
|
<h3>
|
||||||
|
<a href="">
|
||||||
|
📅 {{ post.publicationDate | date }}
|
||||||
|
</a>
|
||||||
|
</h3>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
📍 géolocalisation :<br/>
|
||||||
|
- Longitude : {{ post.longitude }}<br/>
|
||||||
|
- Latitude : {{ post.latitude }}<br/>
|
||||||
|
- Altitude : {{ post.altitude }}<br/><br/>
|
||||||
|
|
||||||
|
💬 Commentaire :<br/>
|
||||||
|
- {{ post.getCommentary }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
29
templates/species/index.html.twig
Normal file
29
templates/species/index.html.twig
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Herbarium - Espèces{% 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>Liste des espèces</h1>
|
||||||
|
|
||||||
|
<dl>
|
||||||
|
{% for specie in species %}
|
||||||
|
<dt>
|
||||||
|
<a href={{ url('app_species') ~ '/' ~ specie.getId }}>
|
||||||
|
🌿 {{ specie.getVernacularName }}
|
||||||
|
</a>
|
||||||
|
</dt>
|
||||||
|
<dd >
|
||||||
|
🔬 Nom Scientifique : {{ specie.getScientificName }}<br/>
|
||||||
|
📍 Region : {{ specie.getRegion }}
|
||||||
|
</dd><br/>
|
||||||
|
{% endfor %}
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Reference in New Issue
Block a user