我想使用下面的代码作为帮助函数,因为它会从我的应用程序中的几个控制器调用。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