create site with form to add offerings

This commit is contained in:
Jannis Portmann 2021-04-28 00:15:13 +02:00
parent 781c8602d9
commit b212d1fa74
4 changed files with 53 additions and 0 deletions

View file

@ -2,6 +2,8 @@
namespace App\Controller;
use App\Entity\Offering;
use App\Form\OfferingFormType;
use App\Repository\OfferingRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -26,4 +28,17 @@ class AppController extends AbstractController
'user' => $this->getUser(),
]);
}
#[Route('/new', name: 'new_listing')]
public function new_listing(): Response
{
$offering = new Offering();
$form = $this->createForm(OfferingFormType::class, $offering);
return $this->render('app/new_listing.html.twig', [
'user' => $this->getUser(),
'offering_form' => $form->createView(),
]);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace App\Form;
use App\Entity\Offering;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class OfferingFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('createdAt')
->add('title')
->add('photoFilename')
->add('zipCode')
->add('description')
->add('byUser')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Offering::class,
]);
}
}

View file

@ -0,0 +1,5 @@
{% extends 'base.html.twig' %}
{% block body %}
{{ form(offering_form) }}
{% endblock %}

View file

@ -31,6 +31,9 @@
<li class="nav-item">
<a class="nav-link" href="{{ path('user_page') }}">User</a>
</li>
<li>
<a class="nav-link" href="#"><i class="fas fa-plus-square"></i> New</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<div class="dropdown-menu" aria-labelledby="navbarDropdown">