2014-12-11 2 views
-1

Ratchet 및 Laravel을 사용하여 websocket 응용 프로그램을 만들고 내 websocket 클래스 내에서 Eloquent 쿼리를 사용해야하지만 다른 네임 스페이스를 사용할 때 웅변을 사용할 수 없습니다. websocket 클래스. 여기 생성 된 클래스/다른 네임 스페이스에서 웅변을 사용하여 laravel에

클래스의 시작에 :

use Illuminate\Auth\UserTrait; 
use Illuminate\Auth\UserInterface; 
use Illuminate\Auth\Reminders\RemindableTrait; 
use Illuminate\Auth\Reminders\RemindableInterface; 
use Ratchet\MessageComponentInterface; 
use Ratchet\ConnectionInterface; 





class Socket extends Eloquent implements MessageComponentInterface, UserInterface, RemindableInterface { 

    use UserTrait, RemindableTrait; 

이는 classmap와 composer.json입니다 :

"autoload": { 
    "classmap": [ 
     "app/commands", 
     "app/controllers", 
     "app/models", 
     "app/database/migrations", 
     "app/database/seeds", 
     "app/tests/TestCase.php", 
     "app/libraries", 
     "vendor/cboden/ratchet/src" // added this 
    ] 

내가 원래 상태에서 composer.json을 변경했습니다 위와 같았습니다 :

... 
"psr-0": {          //removed this 
      "MyApp": "vendor/cboden/ratchet/src", //removed this 
      } 

클래스 소켓은 app/libraries/Socket.php에 있습니다.

흠, 나는 내 마음에 오는 모든 것을 시험해 보았습니다. 누군가 내가 뭘 잘못하고 있는지 생각해 봤습니까?

가 발생 된 오류는 다음과 같습니다

use Socket; 

및 소켓의이 행 15 : 나는 또한했습니다

class Chat extends Eloquent implements MessageComponentInterface, UserInterface, RemindableInterface { 

PHP Warning: The use statement with non-compound name 'Socket' has no effect in /home/michael/PhpstormProjects/preisopt/app/libraries/Socket-Server.php on line 5 

PHP Fatal error: Class 'Eloquent' not found in /home/michael/PhpstormProjects/preisopt/app/libraries/Socket.php on line 15 

이 소켓 - 서버의 라인 5 같은 라인을 작성하려고 시도

class Chat extends \Eloquent implements MessageComponentInterface, UserInterface, RemindableInterface { 

이이 오류가 발생합니다 :

PHP Fatal error: Class 'User' not found in /home/michael/PhpstormProjects/preisopt/app/libraries/Socket.php on line 35 

이 라인 35 :

$dbtoken = User::where('username', '=', $split[1])->get('sockettoken'); 

모든 클래스와 모델이 존재하고이 클래스에서 사용하지 않을 때 노력하고 있습니다. 내가 여기에 시간에 의해 잘못된 몇 가지 이상한 물건이 될 수있는 많은 것들을 시도했습니다

...

+0

'\ Eloquent'가가는 길입니다. 사용자가 네임 스페이스 안에 있습니까? 그렇지 않으면'\ User' 만하십시오. – lukasgeiter

+0

\ DB \ Eloquent를 Eloquent로 사용하십시오. – Anthony

답변

2

귀하의 질문은 조금 복잡하지만, 어떻게 네임 스페이스에 대한 오해로 실행중인 것 같은데 작업.

PHP Warning: The use statement with non-compound name 'Socket' has no effect in /home/michael/PhpstormProjects/preisopt/app/libraries/Socket-Server.php on line 5

는 PHP는 문

use Socket; 

아무것도하지 않는 사실을 말하고있다. use 문을 사용하면 PHP에 "이봐,이 다른 네임 스페이스에서이 네임 스페이스의 클래스를 현재 네임 스페이스로 가져올"것을 알릴 수 있습니다. use Socket라고 말하면 해당 클래스 Socket은 이미 현재 네임 스페이스에 있습니다.your'e가 다른 클래스에 글로벌 클래스 \Socket를 사용하려는 경우, 당신은 당신이 누구의 기본 이름 Socket, 당신은

을 말하고 싶은 다른 네임 스페이스의 클래스를 사용하려는 경우

use \Socket; 

을하고 싶은 말

use Namespace\Path\To\Socket 
//or 
use \Top\Level\Namespace\Path\To\Socket 

파일의 현재 네임 스페이스에 따라 다릅니다.

오류

PHP Fatal error: Class 'Eloquent' not found in /home/michael/PhpstormProjects/preisopt/app/libraries/Socket.php on line 15

PHP Fatal error: Class 'User' not found in /home/michael/PhpstormProjects/preisopt/app/libraries/Socket.php on line 35

만들기 당신이 네임 스페이스 파일 내부에 글로벌 클래스 \Eloquent\User를 사용하려고 시도하는 것 같은 소리입니다. 당신은 당신이 그들을 사용할 때마다 파일의 선두 백 슬래시 이러한 글로벌 클래스 파일의 상단에

use \Eloquent; 
use \User; 

을 추가하거나 참조해야 하나.

+0

자세한 답변을 주셔서 감사합니다. 내 질문도 나를 혼란스럽게했다. – baao

+0

@baao "당신의 질문은 조금 혼란 스럽다." "나는 틀린 질문에 대답하고 있을지도 모른다."라는 코드입니다. –

+0

알아요, 알아요. 그러나 그것은 내 문제에 대한 정확한 정답으로 끝났습니다! – baao

관련 문제