Reputation: 171
I'm new to CodeIgniter, but I'm loving it so far!
I'm in the process of porting over the Shopify API to a CodeIgniter library but I'm running into a small issue that I can't figure out for the life me!
I'm getting an undefined variable error, and I feel like it is something very simple that I am missing, but I can't understand why it isn't working. Here is the relevant code from the custom class:
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]
Here is the code from the config file I created:
/**
* Your shared secret
*/
$config['shared_secret'] = 'changed for posting on forum';
/**
* Your Shopify API key
*/
$config['api_key'] = 'changed for posting on forum';
And here is the relevant code in the controller:
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);
}
}
The error that I get is as follows: A PHP Error was encountered
Severity: Notice
Message: Undefined variable: _api_key
Filename: libraries/Shopify.php
Line Number: 34
So apparently the api key is not getting pulled from the config file even though I have a valid api key? When I do an echo it shows me the whole URL but the API key is not there. I am at a loss as to what to do and would appreciate any help! Thanks!
Upvotes: 1
Views: 260
Reputation: 10964
You've forgotten to add $this
in your shopify_app_install_url()
public function shopify_app_install_url($shop_domain)
{
return "http://$shop_domain/admin/api/auth?api_key={$this->_api_key}";
}
Upvotes: 3