1
votes

I have installed and setup Symfony 3.3.6 on C9.IO.

When I run the app, it loads up and brings me to the default page fine. enter image description here

However I am having a problem adding a a custom controller and view. I've followed all of the instructions, but I get a 404 error when trying to access the page/route. This is the url I'm accessing this page by: https://symfony4-XXXX.c9users.io/test

I've added a controller named TestController.php in the directory src/Controller/TestController.php.

In this controller I have the following code:

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

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

I've added the view 'test.html.twig' to the directory 'app/Resources/views/test/test.html.twig'

The code in this file is:

{% extends 'base.html.twig' %}

{% block body %}
    <p>This is my test page.</p>
{% endblock %}

My routing.yml file is setup as:

app:
    resource: '@AppBundle/Controller/'
    type: annotation

Why can I not access this page? I keep getting a 404 error.

The logs only show:

[2017-08-10 13:00:13] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /test"" at /home/ubuntu/workspace/var/cache/prod/classes.php line 4173 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"GET /test\" at /home/ubuntu/workspace/var/cache/prod/classes.php:4173, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at /home/ubuntu/workspace/var/cache/prod/appProdProjectContainerUrlMatcher.php:47)"} []

1
Have you looked in the log to see for more details?JGrinon
Yes, see the update/edit.Mark

1 Answers

2
votes

Change the annotation

/**
 * @Route("/", name="test")
 */

By this

/**
 * @Route("/test/", name="test")
 */