2015-05-25 92 views
0

我嘗試從mailchimp庫調用函數時看到此錯誤。Codeigniter mailchimp庫問題

A PHP Error was encountered 

    Severity: Notice 

    Message: Undefined property: Api::$Mailchimp 

    Filename: controllers/api.php 

    Line Number: 13 


    Fatal error: Call to a member function call() on a non-object in /home/upul/public_html/mailchimp/application/controllers/api.php on line 13 

我已經做了相應的事情。我不知道爲什麼圖書館沒有創建實例。我知道這是什麼錯誤的手段,但不能看到它爲什麼出現

我的媒體庫的理由(庫/ Mailchimp.php)

class Mailchimp 
    { 
     private $api_key; 
     private $api_endpoint = 'https://<dc>.api.mailchimp.com/2.0/'; 
     /** 
     * Create a new instance 
     */ 
     public function __construct() 
     { 
     $this->ci =& get_instance(); 
     $this->ci->load->config('mailchimp'); 
      $this->api_key = $this->ci->config->item('api_key'); 
      $this->api_endpoint = $this->ci->config->item('api_endpoint'); 
      list(, $datacentre) = explode('-', $this->api_key); 
      $this->api_endpoint = str_replace('<dc>', $datacentre, $this->api_endpoint); 
     } 
     /** 
     * Call an API method. Every request needs the API key, so that is added automatically -- you don't need to pass it in. 
     * @param string $method The API method to call, e.g. 'lists/list' 
     * @param array $args An array of arguments to pass to the method. Will be json-encoded for you. 
     * @return array   Associative array of json decoded API response. 
     */ 
     public function call($method, $args=array()) 
     { 
      return $this->_raw_request($method, $args); 
     } 
     /** 
     * Performs the underlying HTTP request. Not very exciting 
     * @param string $method The API method to be called 
     * @param array $args Assoc array of parameters to be passed 
     * @return array   Assoc array of decoded result 
     */ 
     private function _raw_request($method, $args=array()) 
     {  
      $args['apikey'] = $this->api_key; 
      $url = $this->api_endpoint.'/'.$method.'.json'; 
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
      curl_setopt($ch, CURLOPT_POST, true); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args)); 
      $result = curl_exec($ch); 
      curl_close($ch); 
      return $result ? json_decode($result, true) : false; 
     } 
    } 

我的控制器(控制器/ api.php)

class Api extends CI_Controller { 

     public function __construct() 
     { 
      parent::__construct(); 
      $this->load->library('Mailchimp'); 
     } 

     public function index() 
     { 
      $lists = $this->Mailchimp->call('lists/list'); 
      echo $lists; 
     } 
    } 
+0

您是否已加載適當的幫手? –

+0

我需要加載什麼樣的助手......我已經自動加載了url幫手..這都是 –

+0

你是否手動下載'MailChimp'? –

回答

0

發現問題...

我曾呼籲以大寫字母庫... mailchimp ......應該是mailchimp

問題修正:D