Php Symfony 3.4-服务;AppBundle\Controller\[some]Controller“;依赖于不存在的服务;Symfony\Component\Serializer\Serializer";
(1/1)服务未发现服务异常 “AppBundle\Controller\FormController”依赖于 不存在的服务“Symfony\Component\Serializer\Serializer” 我的控制器是:Php Symfony 3.4-服务;AppBundle\Controller\[some]Controller“;依赖于不存在的服务;Symfony\Component\Serializer\Serializer";,php,symfony,Php,Symfony,(1/1)服务未发现服务异常 “AppBundle\Controller\FormController”依赖于 不存在的服务“Symfony\Component\Serializer\Serializer” 我的控制器是: <?php namespace AppBundle\Controller; use AppBundle\Service\SubscriberService; use Sensio\Bundle\FrameworkExtraBundle\Configuration\R
<?php
namespace AppBundle\Controller;
use AppBundle\Service\SubscriberService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FormController extends Controller
{
private $subscriber;
public function __construct(SubscriberService $subscriber)
{
$this->subscriber = $subscriber;
}
/**
* @Route("/", name="form")
*/
public function indexAction(): Response
{
$categories = $this->subscriber->getCategories();
return $this->render('subscription/form.html.twig', ['categories' => $categories]);
}
/**
* @param Request $request
* @return Response
* @Route("/save", name="save_subscriber")
*/
public function save(Request $request): Response
{
$this->subscriber->save($request->get('name'), $request->get('email'), $request->get('categories'));
}
}
对我来说,这个错误毫无意义。我们可以清楚地看到,控制器中没有这种依赖关系
如何解决这个问题 您的
SubscriberRepository
依赖于序列化程序。由于序列化程序服务在默认情况下不可用,因此您必须将其打开,并在配置中激活它,然后再使用:
# app/config/config.yml
framework:
# ...
serializer:
enabled: true
更多信息:
谢谢 哇,symfony真的应该处理他们的错误消息。非常感谢您的快速回复。我还需要在SubscriberRepository$serializer中以这种方式设置参数:“@serializer”
# app/config/config.yml
framework:
# ...
serializer:
enabled: true