1

我是 CodeIgniter 的新手,但到目前为止我很喜欢它!

我正在将 Shopify API 移植到 CodeIgniter 库,但我遇到了一个小问题,我一生都无法弄清楚!

我收到一个未定义的变量错误,我觉得这是我想念的非常简单的东西,但我不明白为什么它不起作用。以下是自定义类的相关代码:

class Shopify
{

public $_api_key;
public $_shared_secret;
//public $_shops_myshopify_domain;



public function __construct ()
{
    $this->_assign_libraries();

    $this->_api_key                     = $this->config->item('api_key', 'shopify');
    $this->_shared_secret               = $this->config->item('shared_secret', 'shopify');
    //$this->_shops_myshopify_domain        =$this->config->item('shops_myshopify_domain', 'bitauth');
}

public function shopify_app_install_url($shop_domain)
{
    return "http://$shop_domain/admin/api/auth?api_key=$_api_key";
}
 public function _assign_libraries()
 {
    if($CI =& get_instance())
    {
        $this->load     = $CI->load;
        $this->config   = $CI->config;

        $this->load->config('shopify', TRUE);

        return;
    }
 }[/code]

这是我创建的配置文件中的代码:

/**
* Your shared secret
*/
$config['shared_secret'] = 'changed for posting on forum';

/**
* Your Shopify API key
*/
$config['api_key'] = 'changed for posting on forum';

这是控制器中的相关代码:

    Class shopifyPermission extends CI_Controller {
    function __construct ()
    {
        parent::__construct();

        // Load the Shopify API library
        $this->load->library('shopify.php');
        // Require url helper to perform the header redirect
        $this->load->helper('url');
    }

    function index() {
        //require 'shopify.php';

        $shop_domain = "changed.myshopify.com";

        $url = $this->shopify->shopify_app_install_url($shop_domain);

        //redirect($url);

         $data['url'] = $url;

         $this->load->view('shopifyPermission_view', $data);
    }

}

我得到的错误如下: 遇到 PHP 错误

严重性:通知

消息:未定义变量:_api_key

文件名:库/Shopify.php

行号:34

因此,即使我有一个有效的 api 密钥,显然也没有从配置文件中提取 api 密钥?当我执行回显时,它会显示整个 URL,但 API 密钥不存在。我不知道该怎么做,不胜感激!谢谢!

4

1 回答 1

3

您忘记添加$this您的shopify_app_install_url()

public function shopify_app_install_url($shop_domain)
{
    return "http://$shop_domain/admin/api/auth?api_key={$this->_api_key}";
}
于 2012-02-28T22:26:17.470 回答