tailieunhanh - Tương tác giữa PHP và jQuery - part 15

Tạo Phương pháp Store Đối tượng sự kiện trong một Array Bây giờ mỗi sự kiện có thể được lưu giữ như là một đối tượng, bạn có thể tạo ra các phương pháp đó sẽ lặp qua các sự kiện sẵn có và lưu trữ | CHAPTER 4 BUILD AN EVENTS CALENDAR The event ID @var int public id The event title @var string public title The event description @var string public description The event start time @var string public start The event end time @var string public end Accepts an array of event data and stores it @param array event Associative array of event data @return void public function construct event if is array event this- id event event_id this- title event event_title this- description event event_desc this- start event event_start this- end event event end else 141 CHAPTER 4 BUILD AN EVENTS CALENDAR throw new Exception No event data was supplied. Creating the Method to Store Event Objects in an Array Now that each event can be stored as an object you can create the method that will loop through the available events and store them in an array corresponding to the dates on which they occur. First load the event data from the database using _loadEventData . Next extract the day of the month from each event s start date and add a new value to the array at that day s index. In the Calendar class create a new method called _createEventObj and set it to private. Load the events from the database and create the new array using the following bold code php class Calendar extends DB_Connect private _useDate private _m private _y private _daysInMonth private _startDay public function construct dbo NULL useDate NULL . private function _loadEventData id NULL . Loads all events for the month into an array @return array events info private function createEventObj Load the events array arr this- _loadEventData 142 CHAPTER 4 BUILD AN EVENTS CALENDAR Create a new array then organize the events by the day of the month on which they occur events array foreach arr as event day date j strtotime event event_start try events day new Event event catch Exception e die e- getMessage return events Now the events can be loaded and organized in such a way that the method to output the actual .

TỪ KHÓA LIÊN QUAN