PHP 5/MySQL Programming- P61 doc

5 169 0
PHP 5/MySQL Programming- P61 doc

Đang tải... (xem toàn văn)

Thông tin tài liệu

Your code might vary from what you see here, because each theme has a different code fragment for each type of element. The actual details don’t matter as much as the general concept. The notable thing about the code fragment is the lack of any actual content. This is the CMS system hallmark. Rather than displaying any actual values, the code fragments in a theme describe how to display a certain type of text. Notice the placeholders $title and $content. These are, of course, PHP variables that the actual title and content elements will replace. You can modify any of the HTML theme pages as long as you don’t change the name of any of those pages. Likewise, you can replace all of the graphics with your own, but don’t use different names, because the system cannot find them otherwise. Begin with simple changes like color changes and new graphics; get more sophisticated as you begin to understand the file structure. Introducing simpleCMS PHP-Nuke is incredibly powerful, but it’s overkill for many personal Web sites. It was originally designed to be used as a news site, so it’s heavily oriented toward news delivery and online forums. The incredible power of the PHP-Nuke system (and others like it) can also make them very intimidating for new programmers. (Also, I don’t love the coding style used to present the resulting pages. PHP-Nuke relies heavily on HTML tables as a formatting tool rather than the positionable CSS elements I prefer.) TRAP 278 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r FIGURE 8.6 This is the standard look of block.html in the Odyssey theme. I wanted to create a lightweight content management system that provided many of the core features a more complex system provides, but be easier to build and maintain. I actually created two related CMSs, which I describe in the rest of this chapter. The simpleCMS system is easy to use and modify and adds tremendous flexibility to your Web system. You don’t need to learn a single new command in PHP or HTML, but you do need to rethink what a Web page is. Viewing Pages from a User’s Perspective A CMS system is designed to be changed, so although I can show an example of a site using the system, the actual possibilities are much larger than a particular fig- ure will show. Still, Figure 8.7 illustrates how my Web page looks using simpleCMS. This page has a couple of interesting features. It follows a fairly standard design, with three primary segments of the page. A standard banner goes across the top of the page. This banner remains the same even when other parts of the page change. A list of links, which acts as a menu, occupies the left side. You can use multiple menus to support a complex Web hierarchy. The page’s main section contains dynamic content. This part of the page will change frequently. When it changes, however, the other parts of the page will not. The HTML code for the page is combined from three different HTML pages and one CSS style. One (sur- prisingly simple) PHP script controls all the action. 279 C h a p t e r 8 X M L a n d C o n t e n t M a n a g e m e n t S y s t e m s FIGURE 8.7 My main page, simpleCMS-style. Examining the PHP Code Look at the source code for simpleCMS, which is extraordinarily simple: <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2 Final//EN”> <? //Simple CMS //Extremely Simple CMS system //Andy Harris for PHP/MySQL Adv. Beg 2nd Ed. if (empty($menu)){ $menu = “menu.html”; } // end if if (empty($content)){ $content = “default.html”; } // end if include (“menuLeft.css”); include (“top.html”); print “<span class = \”menuPanel\”> \n”; include ($menu); print “</span> \n”; print “<span class = \”item\”> \n”; include ($content); 280 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r COULDN’T I GET THE SAME EFFECT WITH FRAMES? HTML frames were originally designed to allow the same sort of functionality, but frames have proven to be extremely frustrating both for users and develop- ers. It’s reasonably easy to create a frame-based Web site, but much harder to build such a site that behaves well. If you’ve traversed the Web for any time, you’ve bumped into those frames within frames that eventually eat your entire screen away. The Back button acts unpredictably inside a frame context, and it’s difficult to maintain a consistent style across multiple frames. While simpleCMS looks like a frameset, it’s actually all one HTML file generated from a number of smaller files. print “</span> \n”; ?> </body> </html> The code expects two parameters. These parameters are both URLs for HTML files that are displayed by the system. A default value is supplied if either parameter is blank. The core of the program is a series of include statements, which loads and displays a file. The simpleCMS system relies heavily on CSS features including positionable elements and style classes. If you’re rusty on these techniques, look through appendix A, “Reviewing HTML and Cascading Style Sheets.” • The first include loads a CSS style sheet. • The next include loads a page called Top.html. This page (if it exists) appears as a banner across the top of the screen. It is shown for every page in the system. • The other include statements load and display the requested files inside special CSS span elements. If the CSS defines a span class called menuPanel, the $menu page contents are shown according to that style. • Likewise, the $content variable displays according to an item style, if one is defined. By creating these elements as positionable style sheet elements, it’s possible to control where you place objects in addition to any other display specifics. Recall that the div and span tags are special HTML tags that are extremely useful for CSS applications. If you need a refresher on these tags or on CSS, refer to appendix A. Viewing the CSS In a CMS, it’s critical that content and layout remain separate. I’m using CSS as my primary layout management tool. At a minimum, I need to define styles for the menu and content area, because the PHP code is placing text in these ele- ments. You can add any other CSS elements you want. TRAP TRICK 281 C h a p t e r 8 X M L a n d C o n t e n t M a n a g e m e n t S y s t e m s Here’s the basic CSS I used: <!— this style places a menu on the left and an item section in the center. Intended for use with CMS demos for PHP/MySql for the Abs. Beg, Andy Harris —> <style type = “text/css”> body { background-image: url(“binaryBG.gif”) } h1 { color: #0000FF; font-family: “Comic Sans MS”; text-align: center } span.menuPanel { position: absolute; left: 1%; width: 15%; background-color: #CCCCFF } span.item { position: absolute; left: 17%; width: 80%; background-color: #CCCCFF } I defined the background style for all pages created by this system. I also built two span tag subclasses. You may recall that span is useful for CSS because it doesn’t carry any formatting baggage. The span.menuPanel class is defined as a position- able element near the left border that stretches 15 percent of the browser width. The element’s top and height are not defined. This means the element is placed immediately below whatever HTML tag was previously displayed, but all span contents are formatted to fit within the 15-percent limit. I intend for this section of the Web page to be filled with a list of links to serve as a menu. 282 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r . power of the PHP- Nuke system (and others like it) can also make them very intimidating for new programmers. (Also, I don’t love the coding style used to present the resulting pages. PHP- Nuke relies. (sur- prisingly simple) PHP script controls all the action. 279 C h a p t e r 8 X M L a n d C o n t e n t M a n a g e m e n t S y s t e m s FIGURE 8.7 My main page, simpleCMS-style. Examining the PHP Code Look. which is extraordinarily simple: <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2 Final//EN”> <? //Simple CMS //Extremely Simple CMS system //Andy Harris for PHP/ MySQL Adv. Beg 2nd Ed. if (empty($menu)){ $menu

Ngày đăng: 07/07/2014, 02:20

Mục lục

  • PHP 5 / MySQL Programming for the Absolute Beginner

    • Cover

    • Chapter 1: Exploring the PHP Environment

    • Chapter 2: Using Variables and Input

    • Chapter 3: Controlling Your Code with Conditions and Functions

    • Chapter 4: Loops and Arrays

    • Chapter 5: Better Arrays and String Handling

    • Chapter 6: Working with Files

    • Chapter 7: Writing Programs with Objects

    • Chapter 8: XML and Content Management Systems

    • Chapter 9: Using MySQL to Create Databases

    • Chapter 10: Connecting to Databases within PHP

    • Chapter 12: Building a Three-Tiered Data Application

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan