Đang chuẩn bị liên kết để tải về tài liệu:
Tương tác giữa PHP và jQuery - part 17
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
CHAPTER 4 ■ BUILD AN EVENTS CALENDAR Because the markup generation is fairly simple when only using one event, all this method will do is load the desired event by its ID using _loadEventData() and then return the first—and only, due to the LIMIT 1 clause—result from the method. Add the following method to the Calendar class: _loadEventData($id); /* * Return an event object 161 CHAPTER 4 ■ BUILD AN | CHAPTER 4 BUILD AN EVENTS CALENDAR Because the markup generation is fairly simple when only using one event all this method will do is load the desired event by its ID using _loadEventData and then return the first and only due to the LIMIT 1 clause result from the method. Add the following method to the Calendar class php class Calendar extends DB_Connect private _useDate private _m private _y private _daysInMonth private _startDay public function construct dbo NULL useDate NULL . public function buildCalendar . private function _loadEventData id NULL . private function _createEventObj . Returns a single event object @param int id an event ID @return object the event object private function loadEventById id If no ID is passed return NULL if empty id return NULL Load the events info array event this- _loadEventData id Return an event object 161 CHAPTER 4 BUILD AN EVENTS CALENDAR if isset event 0 return new Event event 0 else return NULL When called this method will return an object for the ID of 1 that looks like this Event Object id 1 title New Year s Day description Happy New Year start 2010-01-01 00 00 00 end 2010-01-01 23 59 59 Creating a Method to Generate Markup Now that an array of a single event s data is available you can build a new public method to format the event data into HTML markup. This method will be called displayEvent it will accept an event s ID and generate HTML markup using the following steps 1. Load the event data using _loadEventById . 2. Use the start and end dates to generate strings to describe the event. 3. Return the HTML markup to display the event. Create the displayEvent method by adding the bold code to the Calendar class php class Calendar extends DB_Connect private _useDate private _m private _y 162 CHAPTER 4 BUILD AN EVENTS CALENDAR private _daysInMonth private _startDay public function construct dbo NULL useDate NULL . public function buildCalendar . Displays a given event s information @param int id the event ID @return