Embedding Perl in HTML with Mason Chapter 8: Building a Mason Site-P3
Số trang: 26
Loại file: pdf
Dung lượng: 41.21 KB
Lượt xem: 8
Lượt tải: 0
Xem trước 3 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu embedding perl in html with mason chapter 8: building a mason site-p3, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Embedding Perl in HTML with Mason Chapter 8: Building a Mason Site-P3 Chapter 8: Building a Mason Site-P3• all_projects.htmlThis component actually delegates most of its work to the/search_results.mas component. All this component does is create a cursorrepresenting the rows of interest for this query. In this case, the query issimply all projects . We take advantage of the limit and offsetfeatures of MySQL in order to select only those rows we are interested in.As we shall see in a moment, the /search_results.mas component displayspaged results, 20 per page.In addition, this component needs to get a count of how many rows thisquery would get without the limit. It also creates a textual description of thesearch it is doing so that this can be displayed to the user.The $start and $limit arguments are part of the r esults paging system,and any component that implements a search query must accept them inorder for the paging system to work. $count, projects => $projects, summary => $summary, start => $start, limit => $limit, %ARGS &> $start => 0 $limit => 20 my $summary = all projects; my $count = $Schema->Project_t->row_count; my $projects = $Schema->Project_t->all_rows ( order_by => [ $Schema->Project_t->creation_date_c,desc, $Schema->Project_t->name_c,asc ], limit => [ $limit, $start ], ); - All projects • /search_results.masThis is where the actual work of displaying results is done. This componentis currently used by just two other components, but it is designed so that ifwe add more search options, such as a keyword search, it can handle thoseas well.This component takes the $summary and $count arguments and usesthem to tell the user what kind of search he just did (in case he forgot) andhow many results there were in total.If there are more results than can be shown on one page, it calls the/lib/paging_controls.mas component to do the work of generating links to allthe other pages of results.Finally, if there were results, it loops through the cursor and displaysinformation about each project in turn. Search Results You searched for . There result. % if ($count > $limit) { % } % if ($count) { Name Created on Difficulty Project status % while (my $project = $projects->next) { name | h %> $project->creation_date &> difficulty %> status %> % } % } $count $projects $summary $start $limit • /lib/paging_controls.masGenerating paged search results is a common need in web applications. Ifyou have a database of hundreds, thousands, or more searchable items, youneed a way to handle large result sets. The usual way to do this is to breakthe results into multiple pages, showing a certain number per page with linksto other pages.This component generates the links to the others pages, which looksomething like this: >The link moves one pageforward. The page the user is currently viewing is marked with bold textinstead of being a link. If the user is on the first or last page, the previous ornext page links are not shown.This is all fine until you have something like 100 pages. At that point youneed another level of navigation, so we will end up with something like this: ... > ...The first ... link will move back to the last page of the previous group of10, in this case page 20. The end ... link will move to the beginning of thenext group of 10, in this case, page 31.This design is capable of handling a large number of pages gracefully,although if you anticipated that you would often be generating result setsconsisting of thousands of items, you might want to add additionalnavigation links that allowed the user to jump forward and backward inlarger chunks.One interesting aspect of this component is how it generates its links. Insteadof requiring that a URL be passed in to the component, we use the Apacherequest objects uri() method to determine the current URL. To find outwhat arguments were passed to the page, we use the $m->request_args() method. We do this because we just want toreproduce the arguments passed in by the client, not any generated bycomponent calls earlier in the call stack. We delete the limit and startarguments since we will be overriding them for each link. Displaying results - . ...
Nội dung trích xuất từ tài liệu:
Embedding Perl in HTML with Mason Chapter 8: Building a Mason Site-P3 Chapter 8: Building a Mason Site-P3• all_projects.htmlThis component actually delegates most of its work to the/search_results.mas component. All this component does is create a cursorrepresenting the rows of interest for this query. In this case, the query issimply all projects . We take advantage of the limit and offsetfeatures of MySQL in order to select only those rows we are interested in.As we shall see in a moment, the /search_results.mas component displayspaged results, 20 per page.In addition, this component needs to get a count of how many rows thisquery would get without the limit. It also creates a textual description of thesearch it is doing so that this can be displayed to the user.The $start and $limit arguments are part of the r esults paging system,and any component that implements a search query must accept them inorder for the paging system to work. $count, projects => $projects, summary => $summary, start => $start, limit => $limit, %ARGS &> $start => 0 $limit => 20 my $summary = all projects; my $count = $Schema->Project_t->row_count; my $projects = $Schema->Project_t->all_rows ( order_by => [ $Schema->Project_t->creation_date_c,desc, $Schema->Project_t->name_c,asc ], limit => [ $limit, $start ], ); - All projects • /search_results.masThis is where the actual work of displaying results is done. This componentis currently used by just two other components, but it is designed so that ifwe add more search options, such as a keyword search, it can handle thoseas well.This component takes the $summary and $count arguments and usesthem to tell the user what kind of search he just did (in case he forgot) andhow many results there were in total.If there are more results than can be shown on one page, it calls the/lib/paging_controls.mas component to do the work of generating links to allthe other pages of results.Finally, if there were results, it loops through the cursor and displaysinformation about each project in turn. Search Results You searched for . There result. % if ($count > $limit) { % } % if ($count) { Name Created on Difficulty Project status % while (my $project = $projects->next) { name | h %> $project->creation_date &> difficulty %> status %> % } % } $count $projects $summary $start $limit • /lib/paging_controls.masGenerating paged search results is a common need in web applications. Ifyou have a database of hundreds, thousands, or more searchable items, youneed a way to handle large result sets. The usual way to do this is to breakthe results into multiple pages, showing a certain number per page with linksto other pages.This component generates the links to the others pages, which looksomething like this: >The link moves one pageforward. The page the user is currently viewing is marked with bold textinstead of being a link. If the user is on the first or last page, the previous ornext page links are not shown.This is all fine until you have something like 100 pages. At that point youneed another level of navigation, so we will end up with something like this: ... > ...The first ... link will move back to the last page of the previous group of10, in this case page 20. The end ... link will move to the beginning of thenext group of 10, in this case, page 31.This design is capable of handling a large number of pages gracefully,although if you anticipated that you would often be generating result setsconsisting of thousands of items, you might want to add additionalnavigation links that allowed the user to jump forward and backward inlarger chunks.One interesting aspect of this component is how it generates its links. Insteadof requiring that a URL be passed in to the component, we use the Apacherequest objects uri() method to determine the current URL. To find outwhat arguments were passed to the page, we use the $m->request_args() method. We do this because we just want toreproduce the arguments passed in by the client, not any generated bycomponent calls earlier in the call stack. We delete the limit and startarguments since we will be overriding them for each link. Displaying results - . ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkGợi ý tài liệu liên quan:
-
52 trang 430 1 0
-
24 trang 355 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 314 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 303 0 0 -
74 trang 300 0 0
-
96 trang 293 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 281 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 275 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0