|
Free Open Book
Macromedia Dreamweaver 8 UNLEASHED |
Introduction to PHPIt's hard to argue that PHP Hypertext Preprocessor (PHP) has taken the web development world by storm. PHP is a lightweight, easy-to-learn, and quickly deployed open-source scripting language with a number of convenient features. The language's lineage is Perl, C, and Java, so many developers familiar with those languages will find making the switch very easy. PHP works very well with many database solutions, but it is almost always mentioned in the same breath as the open source MySQL database (discussed with greater detail in the next chapter). PHP can run on Windows, Unix, and Mac servers; it supports IIS, Apache, and other Web servers. As for functionality, PHP 5 has limited support for object-oriented programming, nesting of modules, and custom functions. It has a rich set of built-in tools that let you access XML files, mail servers, database archives, Java APIs and objects, the server's file system, and a lot more. In this section, you'll get a firm grasp on PHP. You'll learn how to install it, how to create a simple page using PHP, understand how IIS and PHP work together, and how to configure a site for use with PHP. Finally, you'll learn about the many features that Dreamweaver exposes for working with PHP as well as configuring Dreamweaver to work with PHP and MySQL together. Installing PHPInstalling PHP is simply a matter of visiting the PHP website, downloading an installer, and running it. Configuring PHP to work in conjunction with Dreamweaver and MySQL is a bit more involved, but that's a process we'll get to later in the chapter. For now, let's walk through the process of installing PHP using the installer so that we can create and process a simple PHP page in the next section. To install PHP, follow these steps: When you've completed the installation, the installer alerts you that script mapping has been set. Essentially, the installer configures IIS so that files with the .php extension are processed using the php-cgi.exe executable located in the C:\PHP folder. Similar to the way asp.dll, asp_isapi.dll, and jrun.dll process their respective pages, php-cgi.exe is the executable used to process PHP pages. Aside from defining script mappings in IIS, the installer places necessary files in the C:\PHP folder. The installer also creates an important configuration file in the C:\Windows folder called php.ini. More on configuring this file in the next chapter. Creating a Simple PHP PageNow that you've had a formal introduction to PHP and you've learned how to install it, let's walk through the process of creating a simple PHP page. Not only will this process help familiarize you with the technology, you'll also get an understanding of how IIS handles the processing of a dynamic PHP pages in conjunction with the php-cgi.exe executable. To create a simple PHP page, follow these steps:
TIP If you plan on trying out numerous server-side technologies, it's beneficial to create the folder with the Dorknozzle name followed by the three-letter server-side technology you plan to use. This convention prevents you from continuously having to redefine the site for every server-side technology. To test your work, open the browser and type the URL http://localhost/DorknozzlePHP/sample.php in the address bar. As you can see from Figure 22.15, two lines of text appear in the browser. Figure 22.15. Two lines of text appear in the browser.
Although this result might not seem all that awe inspiring, think again: You've just created your first dynamic web page using PHP. Look at the code again and see whether you can pick apart the dynamic portions of the page. For the most part, 8 of the 9 lines in the page are plain old HTML that IIS does nothing with. It simply lets the browser parse the HTML tags and presents to the user the text inside them. Line 7, however, works a bit differently: <h1><? echo "This is PHP writing text to the browser dynamically" ?></h1> In this case, we use what's called a code render block to dynamically display the text This is PHP writing text to the browser dynamically within a <h1> HTML tag. IIS, recognizing that this code render block exists, intercepts the request and calls for help from the php-cgi.exe located in the C:\PHP folder. The php-cgi.exe file processes the request and interprets the code render block to mean, "echo, or print out, the text This is PHP writing text to the browser dynamically" on the page. This response is sent back to IIS and ultimately back to the browser, formatted using the <h1> tag. Although the process may seem complex, it happens so fast that a user rarely even knows that a dynamic page is being used. See how easy that was? In this example, we manually wrote PHP code. The beauty in using Dreamweaver is that you don't have to write code at all. Dreamweaver writes all the necessary code for you. More on this later. For now, let's focus on getting our project configured so that we can use PHP to create dynamic Dorknozzle pages. Configuring Dorknozzle to Run Under PHPUp to this point, we've been working primarily from C:\Dorknozzle\<chapterfolder>. From now on, we'll work from C:\Inetpub\wwwroot\DorknozzlePHP (assuming that you're using PHP). Because this is the case, we need to reconfigure the site definition to point to the new folder we've created. Furthermore, we need to configure the Testing Server category in the Site Definition window to provide Dreamweaver with information specific to the technology you plan on using for the defined site. To configure Dorknozzle to run under PHP, follow these steps:
You're now ready to begin building dynamic Dorknozzle pages using Dreamweaver and PHP! Using PHP in DreamweaverDepending on the server technology you decide to use, features exposed in Dreamweaver's interface will change. For the most part, however, you can bank on the fact that the following features are always available when working with any server-side technology:
Earlier, I mentioned that most of the dynamic functionality built into Dreamweaver is the same regardless of the server-side technology you decide to use. This becomes obvious with the Application Objects submenu in the Insert menu and the Application category in the Insert bar. The objects listed in these menus expose generic functionality that remains consistent regardless of server-side technology. What does change is the option below the Application Objects option in the Insert menu. This option (which varies from ASP Object, ASP.NET Objects, ColdFusion Objects, and PHP Objects, depending on which server-side technology you decide to use), changes and displays specific content accordingly. |
Main Menu |
| 500 Juegos Gratis | 500 Giochi Gratis | 500 Jeux Gratuits | 500 Jogos Gratis | 500 Kostenlose Spiele |