我是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
文件名:libraries / Shopify.php
行号:34
显然即使我有一个有效的api密钥,api密钥也不会从配置文件中删除?当我做回声时,它会向我显示整个URL,但不存在API密钥。我不知道该做什么,并将不胜感激任何帮助!谢谢!
答案 0 :(得分: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}";
}