Skip to content

Instantly share code, notes, and snippets.

@anvodev
Created May 5, 2020 01:29
Show Gist options
  • Select an option

  • Save anvodev/8eebefbd9980f09804e57e9fa387250b to your computer and use it in GitHub Desktop.

Select an option

Save anvodev/8eebefbd9980f09804e57e9fa387250b to your computer and use it in GitHub Desktop.
use Lucky service in a controller to return a lucky number
<?php
// src/Controller/DefaultController.php
namespace App\Controller;
use App\Lucky;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="default")
*/
public function index()
{
$lucky = new Lucky();
return $this->json(['number' => $lucky->getNumber()]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment