PHP 5/MySQL Programming- P60 potx

5 257 0
PHP 5/MySQL Programming- P60 potx

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

Thông tin tài liệu

You also learn how to build an even more powerful CMS using a cool technology called XML. I won’t give you a screenshot of that program though, because to the user it looks just like the simple CMS described in Figure 8.2. Understanding Content Management Systems When the Web began, it was conceived as a web of interconnected documents. The ability to link any document to any other was powerful. However, as developers began utilizing the Web, the freeform nature of the Internet sometimes caused headaches. In particular, it became somewhat challenging to manage a large system of related pages, to customize content for individual users, and to maintain consistency in a Web site that might contain hundreds or thousands of documents. Also, the nature of the Web began to change. Instead of simply being a repository of documents, the Web has become a series of interconnected applications. Much of the Web’s content is no longer stored in HTML pages, but is created dynamically by programs such as PHP. CMS has become a popular solution for creating a dynamic Web site that connects many HTML pages and serves them up in a flexible, efficient manner. (Flexibility in this context means the site owner has a lot of options for determining the lay- out and content of the page.) A number of very popular free and commercial CMSs are based on PHP. CMSs frequently include such features like these: • User management. Users can log into the system. A CMS often has multiple user-access levels so some can add content and others can view content. 273 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.2 This CMS is much simpler but still profoundly powerful. • Separation of content into blocks. Content can be grouped into semantic blocks based on its meaning. For example, rather than having arbitrary Web pages as the basic unit, you can organize news stories, Web links, and other elements into HTML pages. • Isolation of layout from content. A CMS usually separates the system content from the layout. This is done for a number of reasons: • The appearance of the entire site should be uniform, even if many people contribute content. • Content developers shouldn’t have to worry about formatting or how to write HTML code. • The layout should be adaptable to handle new designs or technologies. • User-contributed co ontent. Many CMSs include the ability to support online forums and message boards. In addition, you can often grant write access so users can add content to your site. For example, if you’re running a site for a church, you might allow the children’s pastor to directly add content to appropriate parts. You could control access, so people cannot access parts they should not change. You can even allow public access through message forums or automated content management based on individual user preferences. Working with PHP-Nuke PHP-Nuke is one of the most popular open-source CMSs. It uses PHP and MySQL to dynamically generate a Web portal (portal is another term for a customized system meant to be run as the starting place of a Web site). When you get used to PHP-Nuke you notice how many sites run this system or a variant of it. Figure 8.3 illustrates a version of my Web site using PHP-Nuke. PHP-Nuke is an extremely capable CMS system. It supports all the features listed earlier, plus many more. If I log in as the administrator, I get a different display, giving me the opportunity to modify all kinds of options in the site, as shown in Figure 8.4. Any user with appropriate access (determined by the administrator) can alter content by adding news items, surveys, links, and other elements. Additionally, authorized users can change the site’s overall appearance by choosing a new theme, which could include new colors, fonts, icons, and layout. Figure 8.5 demonstrates the main page using a different theme. 274 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 Of course, the real fun comes when you create your own themes or add new mod- ules. Modifying PHP-Nuke is surprisingly simple once you understand the file structure. First things first: Install the system. 275 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.3 I built this professional- looking Web page without writing a single line of PHP code. Thanks, PHP-Nuke. FIGURE 8.4 The administrator can change much of the system’s functionality without any programming. Installing PHP-Nuke A copy of PHP-Nuke is included on the CD that accompanies this book. You might also go directly to the PHP-Nuke Web page (http://phpnuke.org) and ensure you have the latest version of the software. PHP-Nuke is written entirely in PHP and MySQL, so it doesn’t matter which operating system you use. Be sure to install the files in a subdirectory of your Web server’s document root (usually htdocs). PHP-Nuke relies heavily on a series of MySQL tables. (My installation has 92 tables devoted to PHP-Nuke.) Fortunately, you don’t have to install these tables by hand. All the necessary code is in an MySQL script called nuke.sql and is included with PHP-Nuke. Use the MySQL console or phpMyAdmin to run the SQL script. You learn more about how to use these tools in chapter 9, “Using MySQL to Create Databases.” For now, you can simply follow the instructions in the readme file that accompanies PHP-Nuke. You might have to edit the SQL script to change the username, add your own pass- word, or create data tables according to some other scheme. As usual, work with a copy just in case something goes wrong. Read the installation instructions that come with PHP-Nuke; they explain how to set up and test your system. TRAP TRAP 276 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.5 The content is the same, but this new theme uses different colors and graphics. Customizing PHP-Nuke PHP-Nuke installs with a large number of themes and a huge number of options. Play around with your site quite a bit to get everything working the way you want. You’ll still probably make a few changes. As a minimum, you might want to replace some stock images or buttons with custom images. The easiest way to do this is to modify an existing theme: 1. Log in as the administrator by going to the admin.php page in your system. 2. Find the preferences option on this site. 3. Browse through the themes until you find one you want to use as your starting point. 4. Go to your file manager and find the appropriate theme’s folder. 5. In the default installation, look at your PHP-Nuke subdirectory; find the themes under html/themes/. Each theme has its own subdirectory. 6. Duplicate the directory of the theme you want to work with and rename the folder to make the new theme. 7. Go to the theme folder and open theme.php. 8. Search and replace any references to the old theme name with your new theme. Now you can edit any of the HTML files or images in the theme directory to cus- tomize your theme. For example, the blocks.html page controls how a section of the menu on the left side of the screen looks. If you load blocks.html by itself, it might look like Figure 8.6. If you look at the code for block.html, it might look like this: <table border=”0” cellpadding=”3” cellspacing=”0” bgcolor=”#FFFF00” width=”100%”><tr><td align=”left”> <font class=”block-title”><b>$title</b></font> </td></tr></table> <table border=”0” cellpadding=”0” cellspacing=”0” bgcolor=”#ffffff” width=”140”> <tr valign=”top”><td bgcolor=”#ffffff”> $content </td></tr></table> <br> 277 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 . a single line of PHP code. Thanks, PHP- Nuke. FIGURE 8.4 The administrator can change much of the system’s functionality without any programming. Installing PHP- Nuke A copy of PHP- Nuke is included. You might also go directly to the PHP- Nuke Web page (http://phpnuke.org) and ensure you have the latest version of the software. PHP- Nuke is written entirely in PHP and MySQL, so it doesn’t matter. management based on individual user preferences. Working with PHP- Nuke PHP- Nuke is one of the most popular open-source CMSs. It uses PHP and MySQL to dynamically generate a Web portal (portal is

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

Tài liệu liên quan