tailieunhanh - Practical Web 2.0 Applications with PHP phần 7
Chúng tôi sẽ thực hiện các hình thức (và tương ứng xử lý code) cho phép người dùng nhập vào nội dung này, và điều đó một cách chính xác các bộ lọc trình mã HTML để các cuộc tấn công dựa trên JavaScript không có thể xảy ra. Mẫu này cũng sẽ được sử dụng để chỉnh sửa bài viết hiện tại. • | Simpo PDF Merge and Split Unregistered Version - http CHAPTER 10 IMPLEMENTING WEB FEATURES 339 Additionally to ensure that no duplicate tags are inserted we retrieve all tags using getTags and then make them all lowercase using array_map . Finally each tag is inserted into the database. We could instead use hasTag to check whether the new tag already exists but this would result in one lookup query for each tag whereas doing it this way requires only one lookup query. The next function we implement is deleteTags which we use to remove one or more tags from a blog post as shown in Listing 10-5. Listing 10-5. Deleting One or More Blog Post Tags with deleteTagsO public function deleteTags tags if this- isSaved return if is_array tags tags array tags _tags array foreach tags as tag tag trim tag if strlen tag 0 _tags strtolower tag if count _tags 0 return where array post_id . this- getId this- _db- quoteInto lower tag in tags this- _db- delete blog_posts_tags where Just as when inserting tags we must clean up the tags that are passed in which can be either a single tag or an array of tags . Once this has been done we can use the Zend_Db s delete method to remove the matching rows. Finally we include the deleteAllTags method which takes no arguments and removes every tag associated with a single post as shown in Listing 10-6. This is primarily used in the preDelete method which will we update shortly. Listing 10-6. Deleting All of a Post s Tags public function deleteAllTags if this- isSaved return Simpo PDF Merge and Split Unregistered Version - http 340 CHAPTER 10 IMPLEMENTING WEB FEATURES this- _db- delete blog_posts_tags post_id . this- getId . other code As mentioned we must call this function in the preDelete method of DatabaseObject_ BlogPost which is called automatically prior to a blog post being deleted. This is shown in Listing 10-7. We do this so prior to a blog post being deleted the .
đang nạp các trang xem trước