PHP 5/MySQL Programming- P52

PHP 5/MySQL Programming- P52:computer programming has often been seen as a difficult and arcane skill. Programming languages are difficult and complicated, out of the typical person’s reach. However, the advent of the World Wide Web has changed that to some extent. It’s reasonably easy to build and post a Web page for the entire world to see. The language of the Web is reasonably simple, and numerous applications are available to assist in the preparation of static pages | 233 It s not that amazing that the function can generate all that HTML code the code is fairly predictable. What s neat is the way the SuperHTML object knew what its title and headline should be. The phrase Basic Super Page is the string that initializes the SuperHTML object. The buildBottom method is even easier than buildTop because it simply adds some boilerplate page-ending code body html Writing Out the Page The buildTop and buildBottom directives feel a lot like function calls because they are very similar to the functions you ve already created and used many times. However these functions are designed to work within the context of a particular object. A function attached to an object is referred to as a method of the object. A cow object might have moo and giveMilk methods. The syntax for referring to methods in PHP is with the arrow syntax - . There isn t one key to indicate this operator. It is the combination of the dash and the greater-than symbol. Chapter 7 Writing Programs with Objects Note that neither buildTop nor buildBottom actually write any code to the screen. Instead they prepare the page as a long string property inside the object. SuperHTML has a method called getPage that returns the actual HTML code for the page. The programmer can then save the code to a file print it out or whatever. In this case the following line simply prints out the results of the getPage method print s- getPage Working with the Title Property It s possible to designate a title when you create a SuperHTML object but what if you want to change the title later Objects can store code in methods and they can also store data in properties. A property is like a variable attached to a particular object. The SuperHTML object has a title property. The cow object might have a breed property and an age property. The page featured in Figure illustrates this feature. The program begins exactly like the Basic Super page you saw earlier. I even created

Không thể tạo bản xem trước, hãy bấm tải xuống
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.