簡體   English   中英

Codeigniter Mailchimp庫問題

[英]Codeigniter mailchimp library issue

當我嘗試從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

我已經做了相應的一切。 我不知道為什么圖書館沒有創建實例。 我知道此錯誤的含義,但看不到出現此錯誤的原因

我的圖書館(libraries / 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;
        }
    }

我的控制器(controllers / 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;
        }
    }

發現問題...

我用大寫字母給圖書館打電話... Mailchimp ...應該是mailchimp

已解決的問題:D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM