【发布时间】:2012-03-28 23:22:00
【问题描述】:
我在 ./application/helpers 中创建了一个自定义助手,但是我收到了这个错误
无法加载请求的文件 helpers/curl_helper
这是我的帮助文件中的代码:
function send(array $request, $url, $method)
{
//Validating if the required extensions are installed or not
if( !function_exists('json_encode') ) return false;
if( !function_exists('curl_init') ) return false;
//Converting the array into required json format
$request = json_encode($request);
//Setting header required for requests
$header[] = "Content-type: application/json";
$header[] = "Content-length: ".strlen($request) . "\r\n";
//If the request method is get append the data into requests header
if( $method == 'GET' or $method == 'get' ) $header[] = $request;
//Initializing curl
$ch = curl_init();
//Setting curl options for request
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $method );
//If the request method is post add the data we need to enable post
//request and define the data in post fields
if( $method == 'POST' or $method == 'post' ) {
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $request);
}
//Executing the curl request and storing the result in a variable
$result = curl_exec( $ch );
//Closing curl conneciton
curl_close($ch);
return json_decode($result);
}
我正在将它加载到我的库中,例如:
$this->loader =& get_instance();
$this->loader->load->helper('curl');
告诉我哪里做错了?
更新:
当我将函数放在我想使用的同一个库中尝试了太多东西后,我发现行中有错误
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
当我评论这条线功能正常。我不知道错误在哪里,请帮助我。据我认为这是加载程序错误的原因。
【问题讨论】:
-
您是否将您的助手命名为
curl_helper.php? -
Offcourse,我已经尝试过任何一种方式,方法是在子类前缀前面加上前缀并删除它。
-
不带加载器试试看
$this->load->helper('curl'); -
@AntonSementsov 在我删除加载程序时遵循您的建议,我收到以下错误 Undefined property: Video_Api::$load
-
这个答案stackoverflow.com/questions/804399/… 可能会有所帮助。
标签: php codeigniter helpers