Codeigniter Helper函数返回错误
|
我想将以下代码用作辅助函数,因为它将从我的应用程序中的多个控制器中调用。
如您所见,这是一个PHP卷曲,用于将文本发布到用户的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);
当在控制器内部时,此代码可完美工作。但是我想做这样的事情:
将其放在helpers / 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
自动加载。
有任何想法我在这里做错了吗?提前致谢。
没有找到相关结果
已邀请:
2 个回复
乏摩纶誊伟
现在,在控制器,模型或视图中,您必须加载您的自定义帮助程序(或将其放置在application / config / autoload.php
中的自动加载器数组中; ),
现在,您可以按常规方式访问功能了,
挂帘妈乡