我已经阅读了我在SO上找到的所有帖子,但没有一个可以解决我的问题。我收到以下错误:
Call to undefined method Verifybuyback::basic() in /chroot/home/bookcell/bookcellaronline.com/html/CodeIgniter/application/controllers/verifybuyback.php on line 38
这是我的Verifybuyback控制器:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Verifybuyback extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('amz','',TRUE);
$this->load->helper('amazon');
}
function title()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('isbn', 'ISBN','trim|required|xss_clean|callback_title_check' );
if($this->form_validation->run('title')==FALSE)
{
//Field validation failed. User redirected to login page
$this->load->view('buybackmws');
}
else
{
//GOTO RESTRICTED AREAS
redirect('buybackmws', 'refresh');
}
}
function title_check()
{
//Field validation succeeded. Validate against database
$isbn=$this->input->post('isbn');
//QUERY AMAZON FOR THE INFORMATION
$this->basic($isbn); //THIS IS THE LINE WITH THE ERROR!!!!
if($result)
{
$sess_array=array();
foreach($result as $row)
{
$sess_array=array(
'title'=>$row->title,
);
我的amazon_helper.php是:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if (!function_exists('basic')){
function basic($isbn){
$CI = & get_instance();
$CI->load->model('amz','',TRUE);
$parsed_xml=$CI->amz->amazon_xml($isbn);
if($parsed_xml)
{
$amazonResult = array();
$itemCondition = "any";
$current = $parsed_xml->GetMatchingProductForIdResult->Products->Product;//ListMatchingProductsResult
if(isset($parsed_xml->GetMatchingProductForIdResult->Products, $current, $current->AttributeSets)) {
//foreach($current as $offer1){
$offer1=$current;
if(stristr($offer1->AttributeSets->children('ns2', true)->ItemAttributes->Author, "Cram101") != true &&
stristr($offer1->AttributeSets->children('ns2', true)->ItemAttributes->ProductGroup, "Book") == true &&
stristr($offer1->AttributeSets->children('ns2', true)->ItemAttributes->Format, "Kindle eBook") != true)
{
$asin = $offer1->Identifiers->MarketplaceASIN->ASIN;
$amazonResult = array(
'Title' => $offer1->AttributeSets->children('ns2', true)->ItemAttributes->Title,
'SalesRank' => $offer1->SalesRankings->SalesRank->Rank,
'Binding' => $offer1->AttributeSets->children('ns2', true)->ItemAttributes->Binding,
'Weight' => ($offer1->AttributeSets->children('ns2', true)->ItemAttributes->ItemDimensions->Weight),
'ListPrice' => $offer1->AttributeSets->children('ns2', true)->ItemAttributes->ListPrice->Amount,
'ImageURL' => str_replace('SL75','SL200',$offer1->AttributeSets->children('ns2', true)->ItemAttributes->SmallImage->URL),
'DetailURL' => ("http://www.amazon.com/gp/product/" . $asin),//$current->AttributeSets->children('ns2', true)->ItemAttributes->SmallImage->URL,
);
} // end of if
$CI->session->set_userdata('amazon',$amazonResult);
} // END OF ISSET
return TRUE;
}else {
return false;
}
} //END OF AMAZON FUNCTION
}
我的模特amz是:
function amazon_xml($searchTerm) {
$params = array(
'AWSAccessKeyId' => $AWS_ACCESS_KEY_ID,
'Action' => "GetMatchingProductForId",
'SellerId' => $MERCHANT_ID,
'SignatureMethod' => "HmacSHA256",
'SignatureVersion' => "2",
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version'=> "2011-10-01",
'MarketplaceId' => $MARKETPLACE_ID,
'IdType' => "ISBN",
'IdList.Id.1'=> $searchTerm
);
// Sort the URL parameters
$url_parts = array();
foreach(array_keys($params) as $key)
$url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));
sort($url_parts);
// Construct the string to sign
$url_string = implode("&", $url_parts);
$string_to_sign = "GET\nmws.amazonservices.com\n/Products/2011-10-01\n" . $url_string;
// Sign the request
$signature = hash_hmac("sha256", $string_to_sign,$AWS_SECRET_ACCESS_KEY, TRUE);
// Base64 encode the signature and make it URL safe
$signature = urlencode(base64_encode($signature));
$url = "https://mws.amazonservices.com/Products/2011-10-01" . '?' . $url_string . "&Signature=" . $signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
$parsed_xml = simplexml_load_string($response);
return ($parsed_xml);
} //END OF AMAZON_XML FUNCTION
} // END OF CLASS
我已经更改了函数的名称,认为它可能与模型过于相似(以前它是amz_basic,我将其更改为基本版)。我甚至尝试在错误行之前放置load-> helper(amazon),这没有帮助。我做错了什么?
答案 0 :(得分:2)
你可以直接致电basic($isbn);
我的意思是没有$this
。如果该函数不属于帮助文件中的类,则可以在没有$this
的情况下调用辅助函数。