我想使用下面的代碼作爲幫助函數,因爲它會從我的應用程序中的幾個控制器調用。Codeigniter幫助函數返回錯誤
正如你所看到的,這是一個PHP curl文本發佈到用戶的Facebook牆。
} elseif ($this->input->post('post_facebook')) { //"post to facebook" checkbox is ticked
$this->load->model('facebook_model');
$token = $this->facebook_model->get_facebook_cookie();
$attachment = array(
'access_token' => $token['access_token'],
'message' => $post['posts_text'],
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/' . $token['uid'] . '/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close($ch);
這段代碼在控制器內部工作時是完美的。但我想這樣做,而不是:
將這個在助手/ functions_helper.php:
function post_facebook_wall($post) {
$this->load->model('facebook_model');
$token = $this->facebook_model->get_facebook_cookie();
$attachment = array(
'access_token' => $token['access_token'],
'message' => $post['posts_text'],
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/' . $token['uid'] . '/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close($ch); }
然後在我的控制器:
...
} elseif ($this->input->post('post_facebook')) { //post to facebook checkbox is ticked
$post = array('posts_text' => 'sample text');
post_facebook_wall($post);
}
可惜,這是行不通的,我得到一個500錯誤。
functions_helper.php
在自動載入。
任何想法我在做什麼錯在這裏?提前致謝。
什麼在你的error.log? – afarazit 2011-06-14 20:10:22