-1

I have an absolutely clear standart Symfony installation, here's the homepage http://triod.ru/project/web/ (I only changed prod to dev so I could see the logs)

I made a file LuckyController.php in src/AppBundle/Controller directory

<?
// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

class LuckyController
{
    /**
     * @Route("/lucky/number")
     */
    public function numberAction()
    {
        $number = rand(0, 100);

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}

but there's nothing on the page http://triod.ru/project/web/lucky/number The class itself was taken from the Symfony official tutorial/documentation, but it doesn't work. I have no idea how it is possible.

3 Answers3

1

As mentioned above, extending the base class Controller did not work for me. To solve the problem I had to do the following change in web/app.php

$kernel = new AppKernel('prod', true);

Also I had to add 'en' in the url: http://scotchbox.demo/en/lucky/number

Krishna
  • 1,107
  • 1
  • 12
  • 10
0

I think you need to extend the Controller class from symfony to get it working.

class LuckyController extends Controller
{
    /**
     * @Route("/lucky/number")
     */
    public function numberAction()
    {
        $number = rand(0, 100);

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}
Thomas Crawford
  • 886
  • 2
  • 15
  • 45
0

Tommie is right, I just complete your code:

<?php
// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;

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

class LuckyController extends Controller
{
    /**
     * @Route("/lucky/number")
     */
    public function numberAction()
    {
        $number = rand(0, 100);

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}