add form species
This commit is contained in:
@@ -106,7 +106,7 @@
|
|||||||
"symfony/browser-kit": "7.0.*",
|
"symfony/browser-kit": "7.0.*",
|
||||||
"symfony/css-selector": "7.0.*",
|
"symfony/css-selector": "7.0.*",
|
||||||
"symfony/debug-bundle": "7.0.*",
|
"symfony/debug-bundle": "7.0.*",
|
||||||
"symfony/maker-bundle": "^1.0",
|
"symfony/maker-bundle": "^1.59",
|
||||||
"symfony/phpunit-bridge": "^7.0",
|
"symfony/phpunit-bridge": "^7.0",
|
||||||
"symfony/stopwatch": "7.0.*",
|
"symfony/stopwatch": "7.0.*",
|
||||||
"symfony/web-profiler-bundle": "7.0.*"
|
"symfony/web-profiler-bundle": "7.0.*"
|
||||||
|
29
composer.lock
generated
29
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "888e1953f86d0f1fe9b271b85aab0ed0",
|
"content-hash": "c3dc9b5ee79b98f2d1fabe3668860864",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "composer/semver",
|
"name": "composer/semver",
|
||||||
@@ -3507,16 +3507,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/form",
|
"name": "symfony/form",
|
||||||
"version": "v7.0.7",
|
"version": "v7.0.8",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/form.git",
|
"url": "https://github.com/symfony/form.git",
|
||||||
"reference": "b4df6a399a2b03782a0163807239db342659f54f"
|
"reference": "1d0128e2f7e80c346ec51fa4d1ce4fec0d435eeb"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/form/zipball/b4df6a399a2b03782a0163807239db342659f54f",
|
"url": "https://api.github.com/repos/symfony/form/zipball/1d0128e2f7e80c346ec51fa4d1ce4fec0d435eeb",
|
||||||
"reference": "b4df6a399a2b03782a0163807239db342659f54f",
|
"reference": "1d0128e2f7e80c346ec51fa4d1ce4fec0d435eeb",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -3583,7 +3583,7 @@
|
|||||||
"description": "Allows to easily create, process and reuse HTML forms",
|
"description": "Allows to easily create, process and reuse HTML forms",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/form/tree/v7.0.7"
|
"source": "https://github.com/symfony/form/tree/v7.0.8"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -3599,7 +3599,7 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-04-28T11:44:19+00:00"
|
"time": "2024-05-31T14:55:39+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/framework-bundle",
|
"name": "symfony/framework-bundle",
|
||||||
@@ -6887,16 +6887,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/validator",
|
"name": "symfony/validator",
|
||||||
"version": "v7.0.7",
|
"version": "v7.0.8",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/validator.git",
|
"url": "https://github.com/symfony/validator.git",
|
||||||
"reference": "ab4e75b9d23ba70e78480aecbe4d8da15adf10eb"
|
"reference": "23af65dff1f4dfee9aab3a0123a243e40fa3d9cf"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/validator/zipball/ab4e75b9d23ba70e78480aecbe4d8da15adf10eb",
|
"url": "https://api.github.com/repos/symfony/validator/zipball/23af65dff1f4dfee9aab3a0123a243e40fa3d9cf",
|
||||||
"reference": "ab4e75b9d23ba70e78480aecbe4d8da15adf10eb",
|
"reference": "23af65dff1f4dfee9aab3a0123a243e40fa3d9cf",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -6941,7 +6941,8 @@
|
|||||||
"Symfony\\Component\\Validator\\": ""
|
"Symfony\\Component\\Validator\\": ""
|
||||||
},
|
},
|
||||||
"exclude-from-classmap": [
|
"exclude-from-classmap": [
|
||||||
"/Tests/"
|
"/Tests/",
|
||||||
|
"/Resources/bin/"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
@@ -6961,7 +6962,7 @@
|
|||||||
"description": "Provides tools to validate values",
|
"description": "Provides tools to validate values",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/validator/tree/v7.0.7"
|
"source": "https://github.com/symfony/validator/tree/v7.0.8"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -6977,7 +6978,7 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-04-28T11:44:19+00:00"
|
"time": "2024-06-02T15:49:03+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/var-dumper",
|
"name": "symfony/var-dumper",
|
||||||
|
37
src/Controller/SpeciesController.php
Normal file
37
src/Controller/SpeciesController.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use App\Entity\Species;
|
||||||
|
use App\Form\SpeciesType;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
class SpeciesController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/species', name: 'app_species')]
|
||||||
|
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||||
|
{
|
||||||
|
$species = new Species();
|
||||||
|
|
||||||
|
$form = $this->createForm(SpeciesType::class, $species);
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
|
||||||
|
$species = $form->getData();
|
||||||
|
|
||||||
|
$entityManager->persist($species);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
return $this->redirectToRoute('_profiler_home');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('species/species.html.twig', [
|
||||||
|
'form' => $form->createView(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@@ -6,6 +6,7 @@ use App\Repository\SpeciesRepository;
|
|||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: SpeciesRepository::class)]
|
#[ORM\Entity(repositoryClass: SpeciesRepository::class)]
|
||||||
class Species
|
class Species
|
||||||
@@ -16,12 +17,15 @@ class Species
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
private ?string $scientific_name = null;
|
private ?string $scientific_name = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
private ?string $vernacular_name = null;
|
private ?string $vernacular_name = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
private ?string $region = null;
|
private ?string $region = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
28
src/Form/SpeciesType.php
Normal file
28
src/Form/SpeciesType.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Entity\Species;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
|
|
||||||
|
class SpeciesType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('scientific_name')
|
||||||
|
->add('vernacular_name')
|
||||||
|
->add('region')
|
||||||
|
->add('save', SubmitType::class, ['label' => 'Create Species']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => Species::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
20
templates/species/index.html.twig
Normal file
20
templates/species/index.html.twig
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Hello SpeciesController!{% 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/scratch/hupradier1/herbarium/src/Controller/SpeciesController.php</code></li>
|
||||||
|
<li>Your template at <code>/home/scratch/hupradier1/herbarium/templates/species/index.html.twig</code></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
3
templates/species/species.html.twig
Normal file
3
templates/species/species.html.twig
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
|
||||||
|
{{ form_widget(form) }}
|
||||||
|
{{ form_end(form) }}
|
Reference in New Issue
Block a user