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密鑰不在那裏。我很遺憾要做什麼,並希望得到任何幫助!謝謝!
完美補充
$this
!這正是問題所在。非常感謝你的幫助。 – mitchellwright 2012-02-29 00:33:07