我在服务声明中丢失了几天,尤其是当将参数传递给自定义类时。
我有几个扩展和侦听器声明为服务,我将参数传递给构造函数并且正常运行但是对自定义类执行相同操作并且不起作用
错误是该类未在构造函数中接收参数。
错误:
Catchable Fatal Error: Argument 1 passed to Consolidador\PanelBundle\Controller\Integration::__construct() must be an instance of Doctrine\Bundle\DoctrineBundle\Registry, none given, called in /var/www/vhosts/consolidadordeviajes.com/httpdocs/src/Consolidador/PanelBundle/Controller/HotelsController.php on line 149 and defined
这是app/config/services.yml
中所述的服务:
integration:
class: Consolidador\PanelBundle\Controller\Integration
arguments: ['@doctrine', '@session']
这是自定义类:
<?php
namespace Consolidador\PanelBundle\Controller;
use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine;
use Symfony\Component\HttpFoundation\Session\Session;
class Integration
{
private $em;
private $session;
public function __construct(Doctrine $doctrine, Session $session)
{
$this->em = $doctrine->getEntityManager();
$this->session = $session;
}
...
当我调用自定义类时发生错误,我想我正在说明服务并正确收集参数,如果没有,我希望其他人可能会看到我找不到的错误。
致以问候和谢谢。
问题很简单,不是从e lcontendor依赖项中调用自定义类,而是手动尝试instalanciarla。现在我知道服务必须打电话给他们:
$foo= $this->get('service_name');
$foo-Method();