1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP 5/MySQL Programming- P61 doc

5 170 0
Tài liệu đã được kiểm tra trùng lặp

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 188,85 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Your code might vary from what you see here, because each theme has a different code fragment for each type of element.. The notable thing about the code fragment is the lack of any actu

Trang 1

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.)

T R A P

278

g r

s o

l u

g in

e r

FIGURE 8.6

This is the

standard look of

block.html in the

Odyssey theme.

Trang 2

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 simpleCMSsystem 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, Figfig-ure 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

FIGURE 8.7

My main page,

simpleCMS-style.

Trang 3

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

g r

s o

l u

g in

e r C OULDN ’ 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

Trang 4

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 includestatements, 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 includeloads a CSS style sheet

• The next includeloads 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 includestatements load and display the requested files inside

special CSS span elements If the CSS defines a span class called menuPanel,

the $menupage contents are shown according to that style

• Likewise, the $contentvariable displays according to an itemstyle, 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

T R A P

T R I C K

281

Trang 5

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 spantag subclasses You may recall that spanis useful for CSS because it doesn’t carry any formatting baggage The span.menuPanelclass 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

g r

s o

l u

g in

e r

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

TỪ KHÓA LIÊN QUAN