Problem with loading a model / $this->loadModel

Hi, why do i get the following error if I start a Websocket server with: sudo -u www-data php WebSocket.php (the files is located in (src/):

PHP Fatal error:  Uncaught TypeError: rtrim() expects parameter 1 to be string, null given in /var/www/html/vendor/cakephp/cakephp/src/Core/App.php:63
Stack trace:
#0 /var/www/html//vendor/cakephp/cakephp/src/Core/App.php(63): rtrim()
#1 /var/www/html//vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php(291): Cake\Core\App::className()
#2 /var/www/html//vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php(227): Cake\ORM\Locator\TableLocator->_getClassName()
#3 /var/www/html/vendor/cakephp/cakephp/src/Datasource/Locator/AbstractLocator.php(62): Cake\ORM\Locator\TableLocator->createInstance()
#4 /var/www/html//vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php(205): Cake\Datasource\Locator\AbstractLocator->get()
#5 /var/www/html//vendor/cakephp/cakephp/src/Datasource/ModelAwareTrait.php(122): Cake\ORM\Locator\TableLocator->get()
#6 /var/www/html/ in /var/www/html//vendor/cakephp/cakephp/src/Core/App.php on line 63

It seems to have something to do with the $this->loadModel(‘Users’) in src/Controller/Mywebsocketscontroller.php; and it appears with the creation of the object / new MywebsocketsController(); in /src/Websocket.php : if i remove the $this->loadModel(‘Users’) the server will work…

<?php
// in src/WebSocket.php

namespace App;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use App\Controller\MywebsocketsController;



require dirname(__DIR__) . '/vendor/autoload.php'; // Autoload Composer packages



$webSocketServer = IoServer::factory(
    new HttpServer(
        new WsServer(
            new MywebsocketsController()
            )
        ),
    8080 // Port number
    );

$webSocketServer->run();
// in src/Controller/Mywebsocketscontroller.php
<?php

namespace App\Controller;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Cake\Cache\Cache;
use Cake\Http\Session;

class MywebsocketsController extends AppController implements MessageComponentInterface
{
    protected $clients;
    
    protected $userController;
    
    private $users = [];
    

        public function initialize(): void
        {
            parent::initialize();
        
        }
        
        
        
        public function __construct() {
            //         $this->container = $container;
            
            
            $this->clients = new \SplObjectStorage();
            
            
            $xusers = array();
            
            try {
                $this->loadModel('Users');
            } catch(\Exception $e) {
                // Do something with the error, such as log it or display an error message
                $this->log($e->getMessage(), 'debug');
            }

idea?

i personally do not use a controller to run in the websocket. I use a file created in a separate folder like /lib, which doesnt run inside your cake application.

the problem you have is to identify clients to users, but it can be done using tokens as other people have suggested.