2012-05-03 4 views
1

APNS-PHP를 사용하여 PN을 성공적으로 전송했습니다.Code Igniter 프로젝트에 APNS-PHP를 포함시키는 방법은 무엇입니까?

그러나 나는 코드 이그니 터 프로젝트 (명령 줄에서 호출되는 컨트롤러 내부에)을 추가하는 방법에 조금 갇혀 있습니다.

호출 : 오류에

require_once APPPATH.'/third_party/ApnsPHP/Autoload.php'; 

결과 :

Fatal error: Uncaught exception 'Exception' with message 'Class file 
'XXXXXXX/application/third_party/CI/DB/mysql/result.php' does not 
exists' in XXXXXXX/application/third_party/ApnsPHP/Autoload.php:49 

나는 그것이 갈등을 자동 로딩의 어떤 종류의 있으리라 믿고있어? 하지만 나는 진짜로 아니야!

도움이 될 것입니다. 나는 많은 행운없이 Google을 트롤했습니다! 다른 변경

function __autoload($class) 
{ 

    if (strpos($class, 'CI_') !== 0) 
    { 
     if (file_exists($file = APPPATH.'core/'.$class.EXT)) 
     { 
      include $file; 
     } 
     else if (file_exists($file = APPPATH.'libraries/'.$class.EXT)) 
     { 
      include $file; 
     } 
     else if (file_exists($file = APPPATH.'core/base_controllers/'.$class.EXT)) 
     { 
      include $file; 
     } 
    } 
} 
+0

당신이 lib 디렉토리로 사용하기 위해 작성하는 코드를 게시 할 수 있습니까? 어떤 이유로 CI 데이터베이스 클래스를 인스턴스화하려고합니다. –

+0

이온 인증을 위해 다른 곳에서 자동로드 기능을 추가했습니다. 충돌하는 것 같습니다. – Rich

답변

6

: 나는 이온 인증의 libs와로드하기 위해 추가 한 __autoload 기능 여기

require_once APPPATH.'/third_party/ApnsPHP/Autoload.php'; 

것 : 여기

내가 함수 내에서 사용하려고 시도하는 것을 한 라인이다 도서관에, 이것은 나를 위해 작동합니다. 이 CI를 조금 비켜,하지만 여전히 모델로 APNS-PHP에로드 할 수 있습니다 :

<?php 

if(!defined('BASEPATH')) exit('No direct script access allowed'); 

class Notification_model extends CI_Model { 

    protected $apnsDir = ''; 

    // ----------------------------------------------- 

    /** 
    * Setup some basic stuffs 
    * @param void 
    * @return void 
    * @access public 
    */ 
    public function __construct() { 

     parent::__construct(); 

     /* get all the APNS files */ 
     $this->apnsDir = $_SERVER['DOCUMENT_ROOT'].'/application/third_party/ApnsPHP/'; 
     $this->_apns_req(); 

     return; 

    } /* /__construct() */ 

    // ----------------------------------------------- 

    /** 
    * Will send the actual iOS notification to the user 
    * @param $token string iOS device token 
    * @param $msg string 
    * @param $attrs array Key/value pairs to be sent as meta with APN 
    * @return void 
    * @access public 
    */ 
    private function send_ios($token=null, $msg=null, $attrs=array()) { 

     if(!$token || !$msg) return; 

     // Instantiate a new ApnsPHP_Push object 
     $push = new ApnsPHP_Push(
      ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 
      $this->apnsDir.'SSL/server_certificates_bundle_sandbox.pem' 
     ); 

     // Set the Provider Certificate passphrase 
     // $push->setProviderCertificatePassphrase('tablecan29'); 

     // Set the Root Certificate Autority to verify the Apple remote peer 
     $push->setRootCertificationAuthority($this->apnsDir.'SSL/entrust_root_certification_authority.pem'); 

     // Connect to the Apple Push Notification Service 
     $push->connect(); 

     // Instantiate a new Message with a single recipient 
     $message = new ApnsPHP_Message($token); 

     // Set a custom identifier. To get back this identifier use the getCustomIdentifier() method 
     // over a ApnsPHP_Message object retrieved with the getErrors() message. 
     $message->setCustomIdentifier("Message-Badge-3"); 

     // Set badge icon to "3" 
     // $message->setBadge(0); 

     // Set a simple welcome text 
     $message->setText($msg); 

     // Play the default sound 
     $message->setSound(); 

     // Set custom properties 
     if(is_array($attrs) && count($attrs)) 
     { 
      foreach($attrs as $attr_key => $attr_val) 
      { 
       $message->setCustomProperty($attr_key, $attr_val); 
      } 
     } 

     // Set the expiry value - in seconds 
     $message->setExpiry(120); 

     // Add the message to the message queue 
     $push->add($message); 

     // Send all messages in the message queue 
     $push->send(); 

     // Disconnect from the Apple Push Notification Service 
     $push->disconnect(); 

     // Examine the error message container 
     // $aErrorQueue = $push->getErrors(); 
     // if (!empty($aErrorQueue)) { 
     // var_dump($aErrorQueue); 
     // } 

     return TRUE; 

    } /* /send_ios() */ 

    // ----------------------------------------------- 

    private function _apns_req() { 

     require_once $this->apnsDir.'Abstract.php'; 
     require_once $this->apnsDir.'Exception.php'; 
     require_once $this->apnsDir.'Feedback.php'; 
     require_once $this->apnsDir.'Message.php'; 
     require_once $this->apnsDir.'Log/Interface.php'; 
     require_once $this->apnsDir.'Log/Embedded.php'; 
     require_once $this->apnsDir.'Message/Custom.php'; 
     require_once $this->apnsDir.'Message/Exception.php'; 
     require_once $this->apnsDir.'Push.php'; 
     require_once $this->apnsDir.'Push/Exception.php'; 
     require_once $this->apnsDir.'Push/Server.php'; 
     require_once $this->apnsDir.'Push/Server/Exception.php'; 

     return; 

    } /* /_apns_req() */ 

} /* /Notification_model{} */ 

/* End of file notification_model.php */ 
/* Location: ./application/models/notification_model.php */ 

사용 예제를 :

$this->load->model('notification_model'); 
$this->notification_model->send_ios($token, 'Test Message', array('custom_var' => 'val')); 
+0

솔루션처럼 보입니다 - 나는 그 프로젝트에서 Code Igniter를 더 이상 사용하지 않는다고 생각합니다! :/ – Rich

+0

여기서 제 3 자 파일을 얻습니다. 그 링크를주세요. –

관련 문제