上一篇介紹了瀏覽 Google Calendar API 範圍內所有的事件,有沒有發現在 index.php 就有瀏覽單一事件的連結,我們透過 API 可以取得單一事件的 evenID,取得的方式就是透過 basename 函式:
basename($event->id->text)我們可以利用 $_GET 方式讀取到 evenID 值,傳送到 event.php 來接收
$eventId = ( isset($_POST['id']) ) ? $_POST['id'] : $_GET['id'];1. 新增 event.php 檔案,寫入開頭:
where as $where) { $whereValue = $where->valueString;//地點 } ?>
讀取單一事件可寫成一個 getEvent function 到 config.inc.php 檔案,只要傳入 even ID 直進去就可以了。
function getEvent($client, $eventId) { $gdataCal = new Zend_Gdata_Calendar($client); $query = $gdataCal->newEventQuery(); $query->setUser('default'); $query->setVisibility('private'); $query->setProjection('full'); $query->setEvent($eventId); try { $eventEntry = $gdataCal->getCalendarEventEntry($query); return $eventEntry; } catch (Zend_Gdata_App_Exception $e) { var_dump($e); return null; } }2. 編輯事件表格:必須將 event id 寫入 hidden 裡面,傳送到 edit.php 3. 顯示單一事件:
" . $eventEntry->title->text . "\n"; echo "
-
\n";
echo "\t
- 內容:".nl2br($eventEntry->content->text)." \n"; foreach ($eventEntry->where as $where) { echo "\t
- 地點:" . $where->valueString . " \n";//地點 } foreach ($eventEntry->when as $when) { echo "\t
- 開始時間:" . $when->startTime . " \n"; echo "\t
- 結束時間:" . $when->endTime . " \n"; } echo "\t
- 事件ID:".basename($eventEntry->id->text)." \n"; echo "
function updateEvent ($client, $eventId, $newTitle, $where, $desc) { $gdataCal = new Zend_Gdata_Calendar($client); if ($eventOld = getEvent($client, $eventId)) { echo "Old title: " . $eventOld->title->text . "最後把 event.php 檔案,跟 edit.php 檔案程式碼寫在下面,有需要用到的可以拿去用。 event.php:
"; $eventOld->title = $gdataCal->newTitle($newTitle); $eventOld->where = array($gdataCal->newWhere($where)); $eventOld->content = $gdataCal->newContent($desc); try { $eventOld->save(); } catch (Zend_Gdata_App_Exception $e) { var_dump($e); return null; } $eventNew = getEvent($client, $eventId); echo "New title: " . $eventNew->title->text . "
"; return $eventNew; } else { return null; } }
where as $where) { $whereValue = $where->valueString;//地點 } ?> [ 上一頁] [刪除]
" . $eventEntry->title->text . "\n"; echo "
-
\n";
echo "\t
- 內容:".nl2br($eventEntry->content->text)." \n"; foreach ($eventEntry->where as $where) { echo "\t
- 地點:" . $where->valueString . " \n";//地點 } foreach ($eventEntry->when as $when) { echo "\t
- 開始時間:" . $when->startTime . " \n"; echo "\t
- 結束時間:" . $when->endTime . " \n"; } echo "\t
- 事件ID:".basename($eventEntry->id->text)." \n"; echo "
".$newTitle.""; ?>上一篇:
[PHP] Zend 使用 Google Calendar API - 瀏覽事件 下一篇:[PHP] Zend 使用 Google Calendar API - 新增、刪除事件 - END
See also
- 來聊聊 PHP & JavaScript & CSS 的 Coding Style
- 為什麼我選擇使用 Laravel Framework?
- Laravel 搭配 Google, Facebook, Twitter 第三方 OAuth 認證
- 將 wordpress 強制使用 SSL 連線
- PHP 7 vs HHVM Benchmark 比較
- Laravel 50 個小技巧 + Laravel 5.2 新功能
- Laravel Homestead 支援 MySQL 5.7 和 Node 5.0
- PHP-FIG 新網站
- Laravel Homestead 支援 PHP 7
- Laravel 5.1 is released