Open NetBeans, on the left column> LMB over src\AppBundle\Controller folder> New PHP Class> LuckyController

LuckyController.php


<?php
// 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 = mt_rand(0, 100); // this is plain PHP

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

Go to: http://localhost/symfonytest/first_test_symfony/web/lucky/number

It will render – Lucky number: 87 –

You CAN NOT CHANGE:
– namespace use
– class name LuckyController

You CAN CHANGE
– @Route(“/lucky/number”)
– your public function

You HAVE TO:
– return new Response

Example:


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

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

class LuckyController
{
    /**
     * @Route("/lucky")
     */
    public function myAction()
    {
        $numberOne = mt_rand(0, 100); // this is plain PHP
        $numberTwo = mt_rand(0, 100); // this is plain PHP

        return new Response(
            '<html><body>First number: '.$numberOne.' Second number: '. $numberTwo .'</body></html>'
        );
    }
}

Go to: http://localhost/symfonytest/first_test_symfony/web/lucky

First number: 84 Second number: 79