Incident commit avec en plus Form et twig

This commit is contained in:
colesm 2025-04-14 15:22:50 +02:00
parent 8eabb71db4
commit d4928755cd
3 changed files with 74 additions and 0 deletions

33
src/Form/IncidentType.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace App\Form;
use App\Entity\Employee;
use App\Entity\Incident;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class IncidentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('description',
TextareaType::class)
->add('employee', EntityType::class, ['class' => Employee::class, 'choice_label' => 'firstname'])
// ->add('incidentType', EntityType::class, ['class' => IncidentType::class, 'choice_label' => 'id'])
->add('Enregistrer', SubmitType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
// Configure your form options here
]);
}
}

View File

@ -0,0 +1,30 @@
{% extends 'base.html.twig' %}
{% block title %}Incident index{% endblock %}
{% block body %}
<h1>Incident index</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{% for incident in incidents %}
<tr>
<td>{{ incident.id }}</td>
<td>{{ incident.description }}</td>
<td>
<a href="{{ path('incident_show', {'id' : incident.id}) }}">show</a>
<a href="{{ path('incident_edit', {'id' : incident.id}) }}">edit</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('incident_new') }}">Create new</a>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}New Incident{% endblock %}
{% block body %}
<h1>Create new Incident</h1>
{{ form(formNew,{'attr': {'novalidate': 'novalidate'}}) }}
<a href="{{ path('incident_index') }}">back to list</a>
{% endblock %}