我正在为 Symfony 3.4 和自动装配而苦苦挣扎。
他在这里是错误消息的一个例子:
Argument 2 passed to App\Controller\MainController::contact() must be an instance of Swift_Mailer, null given
我作为参数传递的每个服务都是相同的消息。
配置中可能缺少某些东西,但我不知道是什么...
有什么线索吗?
// config/services.yaml
parameters:
google_recaptcha_site_key: '%env(GOOGLE_RECAPTCHA_SITE_KEY)%'
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
App\Controller\:
resource: '../src/Controller'
public: true
tags: ['controller.service_arguments']
// src/Controller/MainController.php
namespace App\Controller;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Validator\Validation;
class MainController extends AbstractController
{
public function contact(
Request $request,
\Swift_Mailer $mailer,
Validation $validation,
) { ... }
}