Commit d1215d45 authored by Mat's avatar Mat

init nouvelle page biere.html, affiche formulaire biere

parent 2dfef772
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Bière</title>
</head>
<body>
<h2>Bière</h2>
<form id="biere">
<label for="nom">Nom</label>
<input type="text" name="nom"><br>
<label for="degre">Degré</label>
<input type="text" name="degre"><br>
<label for="capacite">Capacité</label>
<input type="text" name="capacite"><br>
<label for="brasserie">Brasserie</label>
<select name="brasserie">
</select><br>
<label for="file">Image</label>
<input type="file" name="file">
<button id="send">Envoyer</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.get(
"http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie",
function(data){
for (let item of data) {
$('select[name=brasserie]').append(
`<option value="${item.id}">${item.nom}</option>`
);
}
}
);
});
</script>
</body>
</html>
\ No newline at end of file
<?php
namespace Api2Bundle\Controller;
use Api2Bundle\Entity\Biere;
use Api2Bundle\Form\BiereType;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Request;
class BiereController extends FOSRestController
{
/**
* @param Request $request
* @Rest\Post(path="/biere")
* @Rest\View()
* @return int
*/
public function postAction(Request $request)
{
$biere = new Biere();
$form = $this->createForm(BiereType::class, $biere);
$form->handleRequest($request);
dump($biere);
return 0;
}
}
......@@ -3,6 +3,7 @@
namespace Api2Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Biere
......@@ -24,7 +25,7 @@ class Biere
/**
* @var Categorie
* @ORM\ManyToOne(targetEntity="Api2Bundle\Entity\Categorie")
* @ORM\JoinColumn(name="id_categorie", nullable=false)
* @ORM\JoinColumn(name="id_categorie", nullable=true)
*/
private $categorie;
......@@ -58,7 +59,12 @@ class Biere
* @ORM\Column(name="image", type="string", length=255, nullable=true, unique=true)
*/
private $image;
/**
* @var UploadedFile
*
*/
private $file;
/**
* Get id
......@@ -178,5 +184,23 @@ class Biere
return $this;
}
/**
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
/**
* @param UploadedFile $file
* @return Biere
*/
public function setFile($file)
{
$this->file = $file;
return $this;
}
}
<?php
namespace Api2Bundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class BiereType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nom')
->add('degre')
->add('capacite')
->add('file')
->add('brasserie');
}/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Api2Bundle\Entity\Biere'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return '';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment