【发布时间】:2017-03-20 02:25:25
【问题描述】:
如果有人连接到服务器,我正在使用棘轮和 symfony 2.8 连接到数据库并更改特定列中的值的 Web 套接字应用程序,但我在这一行中遇到错误
$sql = $this->container->get('database_connection');
完整的错误信息
发生错误:注意:未定义属性:check\roomsBundle\Sockets\Chat::$container
我在 services.yml 代码中的注入
services:
database_connection:
class: check\roomsBundle\Sockets\Chat
arguments: ["@service_container"]
我的 Chat.php 代码
<?php
namespace check\roomsBundle\Sockets;
use tuto\testBundle\Entity\Users;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Chat implements MessageComponentInterface {
protected $clients;
//protected $db;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
$sql = $this->container->get('database_connection');
$users = $sql->query("UPDATE user SET ONoff= '1' WHERE UserId='2'");
}
}
【问题讨论】:
标签: php database symfony sockets websocket