TAILIEUCHUNG - Practical Web 2.0 Applications with PHP phần 6

và quản lý các bài đăng trên blog riêng của họ. Trong chương này, chúng tôi sẽ có thêm các chức năng sau đây để ứng dụng web của chúng tôi: • Cho phép người dùng tạo ra các bài đăng trên blog mới. Một bài viết trên blog sẽ bao gồm một tiêu đề, ngày gửi, và nội dung (văn bản hoặc HTML) liên quan tới bài viết. | Simpo PDF Merge and Split Unregistered Version - http CHAPTER 8 EXTENDING THE BLOG MANAGER 279 Figure 8-1. Displaying a summary of posts from the current month Displaying the Monthly Summary Now that we are displaying a summary of posts from the current month we need a way to display posts from the other months. In Listing 8-6 we created the GetMonthlySummary method which gives us an array of months and the number of posts belonging to that month. We will now create a Smarty plug-in to retrieve this data and assign it to the template. We could have generated this data in the indexAction method and then assigned it directly however the problem with this occurs when we want to show the same data on another page. We would have to retrieve and assign the data on every page on which we wanted to display it. This means if we decided to change the layout of the pages we would need to make changes to the PHP code not just the templates. Using a Smarty plug-in allows us to get the data whenever we like. To bring the data from GetMonthlySummary we are going to use Smarty code as follows get_monthly_blog_summary user_id identity- user_id assign summary Effectively what this code means is that we are going to create a custom Smarty function called get_monthly_blog_summary. This function will take two arguments the ID of the user the summary is being fetched for and the name of the template variable to assign the summary to meaning we will be able to access the summary variable in the template after this function has been called . Simpo PDF Merge and Split Unregistered Version - http 280 CHAPTER 8 EXTENDING THE BLOG MANAGER Note The reason we pass in the user ID instead of automatically retrieving it within the plug-in is that by doing it this way we can use this plug-in when displaying users public home pages. Since the ID in that case is dependent on the page being looked at and not which user is viewing the page we specify the ID using the .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.