A
A
Alexander Srokin2018-02-16 14:00:45
symfony
Alexander Srokin, 2018-02-16 14:00:45

How to configure routing in symfony 3 so that page nesting level is unlimited?

Good afternoon!
Is it possible to assign processing of urls with unlimited nesting to one action in symfony?
Or will you still have to limit the nesting and do an action for each level (an example of an action for page 4 of the nesting level below)?

/**
     * @Route("/{part1}/{part2}/{part3}/{part4}", name="simple_page")
     * @param Request $request
     * @param $part1
     * @param $part2
     * @param $part3
     * @param $part4
     * @return Response
     */
    public function pageAction(Request $request, $part1, $part2, $part3, $part4)
    {

        return $this->render('default/index.html.twig', [
            "path1" => $part1,
            "path2" => $part2,
            "path3" => $part3,
            "path4" => $part4
        ]);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2018-02-16
@evil_genius01

page_item:
    path: /{parameters}
    defaults: { _controller: AppBundle\Controller\Page\PageController:itemAction }
    requirements:
        parameters: ".+"

public function itemAction(Request $request, $parameters)
{
    $parts = explode('/', $parameters);
    // ...
}

This code should be at the very end of the list of routes, because it will match any link.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question