Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 条令\ORM\EntityManager,在类MessageComponentInterface中未指定_Php_Symfony_Ratchet - Fatal编程技术网

Php 条令\ORM\EntityManager,在类MessageComponentInterface中未指定

Php 条令\ORM\EntityManager,在类MessageComponentInterface中未指定,php,symfony,ratchet,Php,Symfony,Ratchet,我在symfony 2.8上的项目中使用Ratchet websocket库。 我的问题是如何定义另一个控制器的methode中存在的实体管理器 class WesocketController implements MessageComponentInterface { protected $clients; public function __construct() { $this->clients = new \SplObjectStorag

我在symfony 2.8上的项目中使用Ratchet websocket库。 我的问题是如何定义另一个控制器的methode中存在的实体管理器

class WesocketController implements MessageComponentInterface
{
    protected $clients;

    public function __construct()
    {
        $this->clients = new \SplObjectStorage;
    }

    public function onMessage(ConnectionInterface $from, $msg)
    {
        echo $msg;
        $numRecv = count($this->clients) - 1;
        echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
            , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');

        $myController = new OtherController();
        $myController->test();

        foreach ($this->clients as $client) {
            if ($from !== $client) {
                // The sender is not the receiver, send to each client connected
                $client->send($msg);
            }
        }
    }
}
我在其他控制器中的功能:

public function test()
{
    // echo('yassine');

    $em = $this->getDoctrine()->getManager();

    $newTest = new VisitsTest();
    $newVisitsTest
        ->setTestDate(new \DateTime())
        ->setClient(null);
    $em->persist($newTest);
    $em->flush();
}
错误:

PHP Fatal error:  Uncaught Error: Call to a member function has() on null in MyApp/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
错误在另一个控制器的这一行

$em = $this->getDoctrine()->getManager();
请帮助解决这个问题


谢谢< < /P> < P>控制器动作,考虑


这样,你不会为你调用的每一个动作打开一个新的实体管理器

控制器动作,考虑

这样,您就不会为正在调用的每个操作打开一个新的EntityManager了

,这意味着您的“其他”控制器实际上不是一个控制器,只是一个类,您假设它将像控制器一样工作,因为它扩展了基本控制器类。未注入服务容器。查看2.8文档,了解服务是什么以及如何定义服务。这意味着您的“其他”控制器不是真正的控制器,只是一个类,您假设它将像控制器一样工作,因为它扩展了基本控制器类。未注入服务容器。查看2.8文档,了解什么是服务以及如何定义服务。
public function test(EntityManagerInterface $em){
       $newTest = new VisitsTest();
            $newVisitsTest
                ->setTestDate(new \DateTime())
                ->setClient(null);
            $em->persist($newTest);
            $em->flush();
}