tailieunhanh - Developing Large Web Applications- P21

Developing Large Web Applications- P21:This book presents a number of techniques for applying established practices of good software engineering to web development—that is, development primarily using the disparate technologies of HTML, CSS, JavaScript, and server-side scripting languages. Whereas there are many books on how to use languages, how to use libraries, and how to approach software engineering, this is the first book to codify many of the techniques it presents. These techniques will make the components of your own web applications more reusable, maintainable, and reliable | public function set_mode_compact this- class compact public function set_mode_midsize this- class midsize public function get_content return EOD div id nwcpop class this- class div EOD Multiple Instances of a Module In large web applications multiple instances of the same module often need to appear on the same page. For example suppose you have a paginator containing links for paginating lists across multiple pages that you would like to place at both the top and bottom of a list of search results. Example 7-12 presents one solution using the method set_instance that lets you supply a unique identifier by which to identify each instance of the module. The module appends this unique ID to a base ID for the module to keep all IDs on the page unique. Now because there may be multiple instances of the module on the same page you should also scope the CSS for the module by class name instead of ID see Chapter 4 Scoping within a module on page 58 . To target a specific instance of the module on a page for smaller amounts of additional CSS . different margins for different instances you can use the get_css method for the page to specify the CSS based on the module s ID or you can add CSS scoped to the specific page in your sitewide or sectional CSS file see Chapter 4 Scoping at the page level on page 59 . Example 7-12. Handling multiple instances of the Paginator module class Paginator extends Module protected class protected ident public function construct page . Special Considerations 181 parent __construct page this- class pagint this- ident this- class. def Set up other members for configuring the paginator state based on other arguments passed into the constructor for the module. . public function set_instance instance this- ident this- class. instance public function get_content return EOD div id this- ident class this- class . div EOD _ Dynamic JavaScript and CSS Earlier in the PictureSlider class in Example 7-6 you saw an example that used PHP to generate .