G
G
ganjo8882019-07-22 11:39:48
symfony
ganjo888, 2019-07-22 11:39:48

How to properly work with symfony/routing component?

I'm making a project from scratch, trying to set up routing with the symfony/routing component, as a result I get an empty page when I go to /blog
// congig/routing.php

use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use App\Controller\BlogController;

$collection = new RouteCollection();
$collection->add('blog_list', new Route('/blog', array(
    '_controller' => [BlogController::class, 'list']
)));

return $collection;

// public/index.php
require '../vendor/autoload.php';
require '../config/routing.php';

//App/Controller/BlogController
namespace App\Controller;


class BlogController
{
    /**
     * Matches /blog exactly
     *
     * @Route("/blog", name="blog_list")
     */
    public function list()
    {
        return phpinfo();
    }

    /**
     * Matches /blog/*
     *
     * @Route("/blog/{slug}", name="blog_show")
     */
    public function show($slug)
    {
        
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question