[英]how can I append querystring to object?
Google的日歷API帶來了一些驚喜,現在我需要修復一些奇怪的符號,這些符號會將自己添加到文本中。 我發現此線程恰好描述了我正在處理的問題: http : //www.google.com/support/forum/p/Calendar/thread?tid= 25ac3d762b235a51& hl=zh-CN
解決方法是在“基本” URL提要的末尾附加“&hl = zh-CN”或“?hl = en”。
我對如何做到這一點感到困惑,因為我使用Zend_Gdata將提要作為一個對象進行檢索:
<?php
// load library
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');
// create authenticated HTTP client for Calendar service
$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "xxxxx";
$pass = "xxxxx";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
$gcal = new Zend_Gdata_Calendar($client);
$query = $gcal->newEventQuery();
$query->setUser('xxxxx@group.calendar.google.com');
$secondary=true;
$query->setVisibility('private');
$query->setProjection('basic');
$query->setOrderby('starttime');
$query->setSortOrder('ascending');
//$query->setFutureevents('true');
$startDate=date('Y-m-d h:i:s');
$endDate="2015-12-31";
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$query->setMaxResults(30);
try {
$feed = $gcal->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getResponse();
}
?>
我試圖做到這一點沒有運氣:
$query->setProjection('basic?hl=en');
注意:我之前沒有使用過任何東西,因此如果無法使用,我深表歉意:)
該文檔說, getCalendarEventFeed()
可以將URL作為參數。 所以我們可以改變這個...
$feed = $gcal->getCalendarEventFeed($query);
...以此將參數添加到查詢字符串:
$eventUrl = $query->getQueryUrl() . '?hl=en';
$feed = $gcal->getCalendarEventFeed($eventUrl);
顯然,這是一個簡化的示例-您仍應執行以下兩項檢查:
在對其調用getQueryUrl()
之前,請確保$query
是Zend_Gdata_Query
的實例。
確保沒有其他查詢參數已經添加到$eventUrl
以便我們可以使用&hl=en
而不是?hl=en
。 您可能為此使用Zend_Uri
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.