我为API访问创建了一个库,并为库使用的常用函数创建了一个单独的助手。在codeigniter中,新的库可以通过使用…创建自己的实例来访问本机类。
$example_instance = &get_instance ();
我这样做了,加载了我的helper-但是每次调用helper函数时,我都会得到"试图访问非对象"错误。我做错了什么?
这是我的
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class api_example {
private $api;
public function __construct(){
$this->api = & get_instance();
$this->api->load->helper('helper_test');
}
public function search_recent($param){
$string = $this->api->helper_test->connect($url); //error!!!
return $xml;
}
}
/* End of file */
CodeIgniter helper应该是函数,而不是类。
试试简单的:
$string = connect($url);
这不是从helper调用函数的方式。Helper函数不是CodeIgniter对象的一部分。它们只是函数。
$string = connect($url);