Online Book Reader

Home Category

HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [359]

By Root 1360 0
”>

CS PHP Includes

type = ”text/css”

href = ”csStd.css” />

As you can see, using PHP is almost the same as using the SSI and AJAX approaches from the last two sections of this chapter:

1. Start by building a template.

The general template for all three styles of page inclusion is the same. There’s no need to change the general design or the CSS.

2. Create a small PHP segment for each inclusion.

In this particular situation, it’s easiest to write XHTML code for the main site and write a small PHP section for each segment that needs to be included.

3. Include the HTML file.

Each PHP snippet does nothing more than include the appropriate HTML.


Creating Your Own Data-Based CMS

If you’ve come this far in the chapter, you ought to go all the way and see how a relational database can add flexibility to a page-serving system. If you really want to turn the corner and make a real CMS, you need a system that stores all the data in a data structure and compiles the pages from that structure dynamically. That sounds like a project. Actually, creating your own CMS neatly ties together most of the skills used throughout this book: XHTML, CSS, PHP, and SQL. It’s not nearly as intimidating as it sounds, though.


Using a database to manage content

The first step is to move from storing data in files to storing in a relational database. Each page in a content management system is often the same structure, and only the data is different. What happens if you move away from text files altogether and store all the content in a database?

The data structure might be defined like this in SQL:

DROP TABLE IF EXISTS cmsPage;

CREATE TABLE cmsPage (

cmsPageID INTEGER PRIMARY KEY AUTO_INCREMENT,

title VARCHAR(30)

);

DROP TABLE IF EXISTS cmsBlock;

CREATE TABLE cmsBlock (

cmsBlockID INTEGER PRIMARY KEY AUTO_INCREMENT,

blockTypeID INTEGER,

title VARCHAR(50),

content TEXT,

pageID INTEGER

);

DROP TABLE IF EXISTS blockType;

CREATE TABLE blockType (

blockTypeID INTEGER PRIMARY KEY AUTO_INCREMENT,

name VARCHAR(30)

);

DROP VIEW IF EXISTS pageView;

CREATE VIEW pageView AS

SELECT

blockType.name as ‘block’,

cmsBlock.title as ‘title’,

cmsBlock.content as ‘content’,

cmsBlock.pageID as ‘pageID’,

cmsPage.title as ‘page’

FROM

cmsBlock, blockType, cmsPage

WHERE

cmsBlock.blockTypeID = blockType.blockTypeID;

INSERT INTO cmsPage VALUES (

null,

‘main page’

);

INSERT into blockType VALUES (null, ‘head’);

INSERT into blockType VALUES (null, ‘menu’);

INSERT into blockType VALUES (null, ‘content1’);

INSERT into blockType VALUES (null, ‘content2’);

INSERT into blockType VALUES (null, ‘footer’);

INSERT INTO cmsBlock VALUES (

null,

1,

‘it\’s a binary thing’,

null,

1

);

INSERT INTO cmsBlock VALUES (

null,

2,

‘menu’,

‘,

1

);

INSERT INTO cmsBlock VALUES (

null,

3,

‘Book I - Creating the XHTML Foundation’,

  1. Sound XHTML Foundations
  2. It\’s All About Validation
  3. Choosing your Tools
  4. Managing Information with Lists and Tables
  5. Making
Return Main Page Previous Page Next Page

®Online Book Reader