M
M
Messi2019-05-17 10:13:33
symfony
Messi, 2019-05-17 10:13:33

Routing in Symfony for bundle?

Hello! I understand Symfony 3.4, but I can't figure out how to add a route for the controller.
Added bundle to routing.yml

user:
    resource: '@UserBundle/Controller/'
    type: annotation

The User bundle has a Controller folder, and in it I created LoginController.php
namespace UserBundle\Controller;


use FOS\UserBundle\Doctrine\UserManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use UserBundle\Entity\User;

/**
 * Class LoginController
 *
 * @package UserBundle\Controller
 *
 * @Route("/login", name="login_")
 */
class LoginController extends Controller
{
    /**
     * Matches / exactly
     *
     * @Route("/", name="login")
     */
    public function index(Request $request)
    {
        return new Response(
            'Welcome '
            Response::HTTP_OK,
            ['Content-type' => 'application/json',]
        );
    }
}

Trying to go:
my.local/user/login
my.local/user/
Getting 404. Why? Please tell me how to solve.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2019-05-17
@FitTech

When importing routing, specify prefix: /user, can be found in the official documentation . Then the page will be available at: my.local/user/login/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question