Перейти к основному содержанию

URL & HTTP

Пример указания главной страницы

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class HomeController extends AbstractController
{
    /**
     * @Route("/", name="home")
     */
    public function index()
    {
        return $this->render('home/index.html.twig', [
            'controller_name' => 'HomeController',
        ]);
    }
}

Пример указания числового ID для страницы

<?php

namespace App\Controller;

use App\Entity\Product;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class ProductController extends AbstractController
{
    /**
     * @Route("/products", name="products")
     */
    public function index()
    {
        return $this->render('product/index.html.twig', [
            'controller_name' => 'ProductController',
        ]);
    }

    /**
     * @Route("/product/{id}/", name="product")
     */
    public function product() // shop/index.php?productID=23453
    {
        $product = $this->getDoctrine()->getRepository(Product::class)->find(20950);

        return $this->render('product/index.html.twig', [
            'product' => $product,
        ]);
    }

}