Lưu ý đối tượng Zend_Db_Select là một API SQL được sử dụng để lập trình xây dựng các truy vấn. có một số lợi thế của việc sử dụng API này chứ không phải là văn bản SQL. Có lẽ quan trọng nhất là một thực tế rằng đối tượng Chọn sẽ thích ứng với | CHAPTER 4 MANAGING DATA WITH ZEND FRAMEWORK Note The Zend_Db_Select object is an SQL API that is used to programmatically build queries. There are several advantages of using this API rather than writing SQL. Probably the most important is the fact that the Select object will adapt the SQL depending on the database adapter you are using which makes the code more portable. Listing4-9. ThefetchBugs Method in application models public function fetchBugs _ select this- select return this- fetchAll select Adding the List Action to the Bug Controller Now that you have a method to fetch all the bugs from the database you are ready to start working with them. So create a list action in the bug controller. Use the Zend_Tool line in Listing 4-10 to create the action and view. Listing 4-10. Creating the List Action with ZendTool zf create action list bug Now open the bug controller to update this action. For the time being this will just create a new instance of the Bug model and pass the results of the fetchBugs method to the view to render as shown in Listing 4-11. Listing4-11. ThelistAction Method in application controllers public function listAction bugModel new Model_Bug this- view- bugs bugModel- fetchBugs Creating the List View To create the list view open application views scripts bug . This view script will render a table with all the current bugs. To render this table it will use the partialLoop view helper which takes a data set and passes each item in the set to the partial script that you specify see Listing 4-12 . 60 Download at CHAPTER 4 MANAGING DATA WITH ZEND FRAMEWORK Listing 4-12. The List View Script in application views scripts bug h2 Current Bugs h2 table class spreadsheet cellspacing 0 tr th nbsp th th Date th th Priority th th Status th th URL th th Submitter th th Description th tr php echo this- partialLoop bug this- bugs table Now you need to create the view