我正在尝试将Zend日历库访问对象(即“服务”)存储在codeigniter控制器中,该控制器可以在控制器内的任何功能中访问以供将来使用。我试图将它存储在一个类变量中,并将其作为“$ this-> service”访问,但该对象返回为空。下一个技术是将对象存储在session中,该对象也返回一个空变量。我编写的对象的会话存储代码如下:
我的控制器:
class calendar extends CI_Controller {
function __construct(){
parent::__construct();
$clientPath = APPPATH."libraries";
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientPath);
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
}
public function connect_with_google(){
// User whose calendars you want to access
$user = 'email@email.com';
$pass = 'mypassword';
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$service = new Zend_Gdata_Calendar($client);
$this->session->set_userdata('service', $service);
}
public function ajax_get_calendars()
{
var_dump($this->session->userdata('service'));
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */