Reputation: 203
I got a problem in new symfony 4.
<?php
namespace App\Controller;
use App\Entity\Flight;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use App\Form\FlightType;
use Symfony\Component\Translation\Translator;
use Symfony\Component\HttpFoundation\Request;
/**
* Class DefaultController
* @package App\Controller
*/
class DefaultController extends Controller
{
/**
*
* @Route("/")
* @Route("/{_locale}/", name="homepage", requirements={"_locale" = "%app.locales%"})
*
* @param Translator $translator
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function index(Translator $translator, Request $request)
{
$translated = $translator->trans('Symfony is great');
Error: Controller "App\Controller\DefaultController::index()" requires that you provide a value for the "$translator" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.
Configs: service.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: false
...
App\Controller\:
autowire: true
resource: '../src/Controller'
tags: ['controller.service_arguments']
translation.yaml
framework:
default_locale: '%locale%'
translator:
paths:
- '%kernel.project_dir%/translations'
fallbacks: ['en']
Whats wrong? Manual here: http://symfony.com/doc/current/translation.html
Upvotes: 1
Views: 3945
Reputation: 203
Found the answer.
Upvotes: 3