N
N
Nubbin2017-07-31 11:17:49
symfony
Nubbin, 2017-07-31 11:17:49

Symfony Route not working?

Good afternoon, I started learning Symfony here, how to create pages for the router correctly.
That's not how it works.

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request)
    {
        // replace this example code with whatever you need
        return $this->render('default/index.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
        ]);
    }

    /**
     * @Route("/page" name="page")
     */
    public function pageAction(Request $request) {
        return $this->render('default/page.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
        ]);
    }
}

The first method redirects to the main page and a 404 error is displayed on the page.
If you do this: then it works, but return everything as it is, then again 404 error //routing.yml$kernel = new AppKernel('prod', true);
$kernel = new AppKernel('prod', false);
app:
    resource: '@AppBundle/Controller/'
    type: annotation

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Kuznetsov, 2017-07-31
@Nubbin

Have you rebuilt the cache?

A
Anton1863, 2021-01-06
@Anton1863

Even though the issue has already been resolved. But for those who will still face the problem and will not find a solution. On Symfony 5, I did not have all the routes except the root one, it turned out that I had to put "FallbackResource /index.php" in the Apache config (of course, this is only for those cases if you have an apache web server) where "Directory". Actually, this problem is covered on the official website.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question