2012-03-12 49 views
2

我創造了./application/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'); 

告訴我我在哪裏做錯了?

UPDATE:
嘗試了太多的事情,當我在同一個庫把功能,我想用我發現,在該線路的錯誤後

curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 

當我評論這個線功能正常工作。我不知道錯誤在哪裏,請幫助我。就我認爲這是裝載機錯誤的原因。

+0

你給你的助手'curl_helper.php'命名了嗎? – 2012-03-12 14:42:10

+0

Offcourse和我已經嘗試在任何方式意味着通過前綴子類前綴和刪除它。 – 2012-03-12 14:43:18

+0

嘗試它沒有加載器'$ this-> load-> helper('curl');' – 2012-03-12 14:45:21

回答

1

好吧,如果你使用的是"MY_helpername"然後做檢查,如果你命名你的服務器上的文件爲「my_helpername」,我不知道原因,但CI會尋找my_helpername.php在助手文件夾,但不能MY_helpername 。我在過去有這個問題,並將我的linux機器上的名稱從MY_helpername更改爲my_helpername爲我工作。

希望這有助於

+0

是的,我已經做了這個不知道是否符合標準或不,但我終於來到這個解決方案。 – 2012-05-11 09:35:31

3

您使用的是CodeIgniter> = v 2.0.3嗎?檢查代碼點火器加載程序代碼,我只能看到幫助程序加載失敗的幾種方法:

  • 文件命名錯誤。您的文件必須具有.php擴展名,即。 curl_helper.php,但似乎你已經檢查過了。
  • 文件不在正確的位置(應用程序/幫助程序)。再一次,似乎你已經檢查過了。
  • 正在運行的Web服務器無法訪問文件。權限問題?
  • 子類前綴:子類前綴是什麼配置設置 ?這是默認設置:

    $ config ['subclass_prefix'] ='MY_';

    CI允許用戶通過將默認助手設置爲前綴來覆蓋其默認助手。例如,你可以通過一個名爲MY_array_helper.php的文件覆蓋數組助手。如果碰巧你的助手匹配了子類前綴,那麼CI假定你正在嘗試覆蓋系統助手,並試圖確保該助手存在於系統助手目錄中。例如,如果您在application/helpers/MY_curl_helper.php中有幫助程序,那麼CI會檢查system/helper/curl_helper.php中是否存在幫助程序。換句話說,確保你的助手的文件不符合子類前綴。

+0

我已經更新了我的問題,請檢查並幫助我,如果你可以... – 2012-03-13 07:46:17

+0

你怎樣調用send()函數?有一件事我可以看到可能是一個問題,當函數使用GET時,它會將JSON字符串附加到$ request,但這會導致無效的HTTP標頭 – RobertoP 2012-03-14 18:04:02

-1

解決方案:對於我來說,重命名小寫的文件,工作正常。

+0

還有另外一個答案(事實上接受的答案)就是說你剛纔說的同一件事。 – 2013-09-12 00:40:33