2017-01-05 2 views
1

그래서 CodeIgniter를 사용하여 wamp 서버에서 Pusher와 작업하는 데 문제가 있습니다. 클라이언트 측은 정상적으로 작동하지만 PHP는 이벤트를 trigg하지 않습니다. PHP는 채널을 인증하지만 이벤트는 트리거하지 않습니다. Pusher 이벤트 작성자 클라이언트를 사용하면 이벤트가 발생합니다.로그하는 방법 CodeIgniter에서 Pusher PHP 이벤트 트리거가 실패합니까?

function send_event($channel, $event, $message, $socket_id = NULL){ 
    $channel_array = array(); 
    array_push($channel_array, $channel); 
    $data['message'] = $message; 
    if(is_null($socket_id)){ 
     $response = $this->pusher->trigger($channel_array, $event, $data); 
    }else{ 
     $response = $this->pusher->trigger($channel_array, $event, $data, $socket_id); 
    } 
    var_dump($response);   
} 

하면 FALSE를 반환 위해서 var_dump : 여기

는 코드입니다. 내가 더 문제를 이해하고 싶지만 디버깅하는 방법에 붙어있다. 푸셔에서 PHP 문서

class MyLogger { 
    public function log($msg) { 
    print_r($msg . "\n"); 
    } 
} 

$pusher->set_logger(new MyLogger()); 

그러나이 코드를 사용하면 CI 오류가 발생합니다. 나는이처럼 내 미는 라이브러리에 myLogger를 사용하려고 :

function __construct() 
    { 
     class MyLogger { 
      public function log($msg) { 
      print_r($msg . "\n"); 
      } 
     } 

     $this->CI =& get_instance(); 
     $this->CI->load->library('tank_auth'); 

     require_once('Pusher.php'); 

     $this->options['encrypted'] = true; 
     $this->pusher = new Pusher(
      $this->key, 
      $this->secret, 
      $this->app_id, 
      $this->options 
     ); 
     $logger= new MyLogger; 
     $this->pusher->set_logger($logger); 
    } 

    function send_event($channel, $event, $message, $socket_id = NULL){ 
     $channel_array = array(); 
     array_push($channel_array, $channel); 
     $data['message'] = $message; 
     if(is_null($socket_id)){ 
      $response = $this->pusher->trigger($channel_array, $event, $data); 
     }else{ 
      $response = $this->pusher->trigger($channel_array, $event, $data, $socket_id); 
     } 
     var_dump($response);   
    } 

하지만 오류가있어 :

Class declarations may not be nested 
+0

당신은 클래스의 내부 클래스를 선언 할 수 없습니다 :

는 그것은 gobal 범위 또는 네임 스페이스에 선언해야합니다. – yivi

답변

0
function __construct() 
{ 
    class MyLogger { 
     public function log($msg) { 
     print_r($msg . "\n"); 
     } 
    } 
} 

이 유효하지 않은 코드는, 당신은 함수 또는 다른 클래스의 내부 클래스를 선언 기운을.

// declare first class 
class MyLogger { 
    public function log($msg) { 
     print_r($msg . "\n"); 
    } 
} 

// now you can instantiate the class inside you second class 
class PusherOrWhatever { 
    public function __construct() { 
     $this->pusher->set_logger(new MyLogger); 
    } 
}