Start on the fridge frontend
Create list overview without styling Start on editer of fridge
This commit is contained in:
parent
60577f15fe
commit
725fa47c6d
34
src/Controller/FridgeController.php
Normal file
34
src/Controller/FridgeController.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Fridge;
|
||||
use App\Form\FridgeType;
|
||||
use App\Repository\FridgeRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
#[Route('/fridge', name: 'fridge')]
|
||||
class FridgeController extends AbstractController
|
||||
{
|
||||
#[Route('/list', name: '_list')]
|
||||
public function list(FridgeRepository $repo)
|
||||
{
|
||||
$fridges = $repo->findAll();
|
||||
|
||||
return $this->render('fridge/list.html.twig', [
|
||||
'fridges' => $fridges,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/single/{fridge}', name: '_single')]
|
||||
public function single(Fridge $fridge, Request $request)
|
||||
{
|
||||
$form = $this->createForm(FridgeType::class, $fridge);
|
||||
|
||||
return $this->render('fridge/single.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
29
src/Form/FridgeType.php
Normal file
29
src/Form/FridgeType.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Fridge;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class FridgeType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('description')
|
||||
->add('productLines')
|
||||
->add('save', SubmitType::class)
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Fridge::class,
|
||||
]);
|
||||
}
|
||||
}
|
@ -2,7 +2,8 @@
|
||||
<div class="container-fluid">
|
||||
<i class="bi-shop" style="font-size: 2rem; padding-right: 0.5rem; color: white;"></i>
|
||||
<a class="navbar-brand" href="#">IceCold</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse"
|
||||
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||||
@ -11,8 +12,14 @@
|
||||
<a class="nav-link active" href="{{ path('home') }}">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ path('admin') }}">Admin</a>
|
||||
<a class="nav-link" href="{{ path('fridge_list') }}">Fridges</a>
|
||||
</li>
|
||||
|
||||
{% if is_granted('ROLE_ADMIN') %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ path('admin') }}">Admin</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<ul class="navbar-nav ms-auto mb-2 mb-md-0">
|
||||
{% if is_granted('ROLE_USER') %}
|
||||
|
8
templates/fridge/list.html.twig
Normal file
8
templates/fridge/list.html.twig
Normal file
@ -0,0 +1,8 @@
|
||||
{% extends "base/base.html.twig" %}
|
||||
|
||||
{% block body %}
|
||||
Fridges: <br>
|
||||
{% for fridge in fridges %}
|
||||
<a href="{{ path('fridge_single', {'fridge': fridge.id}) }}">{{ fridge.name }}</a> <br>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
5
templates/fridge/single.html.twig
Normal file
5
templates/fridge/single.html.twig
Normal file
@ -0,0 +1,5 @@
|
||||
{% extends "base/base.html.twig" %}
|
||||
|
||||
{% block body %}
|
||||
{{ form(form) }}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user