Skip to content
Snippets Groups Projects
Commit 0b4d45fe authored by Axel Po's avatar Axel Po
Browse files

feat: label post

parent 5af8bb1a
Branches
2 merge requests!6Dev,!3Feat/categories
......@@ -9,17 +9,29 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\CategoryRepository;
#[Route('/admin/product')]
class ProductController extends AbstractController
{
#[Route('/', name: 'app_product_index_admin', methods: ['GET'])]
public function index(ProductRepository $productRepository): Response
public function index(Request $request, ProductRepository $productRepository, CategoryRepository $categoryRepository): Response
{
$category = $request->query->get('category');
if($category == null) {
$products = $productRepository->findBy([], ['id' => 'DESC']);
} else {
$products = $productRepository->findByCategory($category, ['id' => 'DESC']);
}
$categories = $categoryRepository->findAll();
return $this->render('product/index.html.twig', [
'products' => $productRepository->findBy([], ['id' => 'DESC'])
'products' => $products,
'categories' => $categories,
'selectedCategory' => $category
]);
}
#[Route('/new', name: 'app_product_new', methods: ['GET', 'POST'])]
public function new(Request $request, ProductRepository $productRepository): Response
......
......@@ -8,18 +8,15 @@
>Ajouter un item</a
>
</div>
<label class="inline-flex mt-6" for="pet-select"
>Trier les produit par catégorie :</label
>
<select name="pets" id="pet-select">
<option value="">--Please choose an option--</option>
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="hamster">Hamster</option>
<option value="parrot">Parrot</option>
<option value="spider">Spider</option>
<option value="goldfish">Goldfish</option>
</select>
<form class="mt-4" action="{{ path('app_product_index_admin') }}" method="GET">
<label for="category-select">Trier les produits par catégorie :</label>
<select name="category" id="category-select" onchange="this.form.submit()">
<option value="">-- Toutes les catégories --</option>
{% for category in categories %}
<option value="{{ category.id }}" {% if category.id == app.request.query.get('category') %}selected{% endif %}>{{ category.name }}</option>
{% endfor %}
</select>
</form>
</div>
<section class="flex flex-col gap-y-6">
......@@ -30,7 +27,7 @@
<div class="flex flex-col md:flex-row md:items-center">
<p class="text-xl">{{ product.id }}</p>
<p class="md:ml-12">{{ product.title }}</p>
<p class="md:ml-12">Catégorie</p>
<p class="md:ml-12">{{ product.category.getName() }}</p>
</div>
<div class="mt-6 md:m-0">
......
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