Creating A PHP-Based Content Management System

Published on: July 6, 2004
Last Updated: July 6, 2004

Creating A PHP-Based Content Management System

Published on: July 6, 2004
Last Updated: July 6, 2004

If you’re going to run an intranet site, then you’ll probably want a content management system (CMS) — a tool used to organize documents and keep track of what’s where.

I’ve covered a plethora of such systems in previous articles, but for many businesses there can be only one solution: to design and implement their own custom system.

Why? It’s not like the off-the-shelf systems lack features or stability. On the contrary, many have been crafted by hundreds of man-hours of work, and are successfully implemented by thousands of Web sites and intranets.

But when it comes down to it, it’s hard to have much clue as to how they work. If you want to customize the way these systems operate, you’ll often have to wade through vast amounts of (often badly documented) code to find what needs changing.

Writing your own CMS, on the other hand, can lead to a solution that is better suited to your requirements, better addresses the needs of your users, and is better understood by your development team.

If you have the time and expertise to write your own in-house system, it may well prove the better option. And this is what I shall be embarking upon in this series.

The system we create will be written using the PHP programming language, which excels in the development of Web-based systems.

I’ll be using MySQL as the database server, but the system will be written to allow the use of alternative databases, such as PostgreSQL or SQL Server.

So what will this system actually do? First and foremost, it will allow the bulk of the intranet or Internet site’s content to be easily stored and managed in a database.

We’ll also include a number of other features required for running a successful site, such as authenticating users and managing files.

Some basic PHP knowledge will be needed for coding your own CMS, although most of what you’ll need to know will be demonstrated here.

I’ll assume you have access to a server running PHP and a database system. Once the series is complete, I’ll make available a polished version of the CMS for anyone to use.

I don’t promise the vast array of abilities incorporated into systems such as Postnuke, Smarty, or some commercial content management systems.

But just having lots of features isn’t always what’s needed, and this series will help you to develop a system specifically targeted to your needs. With that, let’s get going…

Planning The CMS

To begin with, we’ll plan how our PHP-based content management system will work.

In subsequent articles, I’ll demonstrate how each of the major components are implemented, leading to a complete system.

The first step is a basic specification of what our CMS must do. Obviously, this will depend on your needs:

Content Management: Probably the most vital function of the system, it must store content such as documents and news in a database, and display to the user whatever he or she requests.

An easy-to-use interface is required to allow editors to add, remove, or modify content.

User authentication: There may be certain areas of the intranet or Internet site to which we wish to limit access.

At the very least this will be the “admin” area, where the editor of the site will be able to add, edit or modify content. You may also wish to have areas only available to certain departments or staff.

Page uniformity/templates: The system should have a uniform look and feel, and this design element needs to be separated from the logic element, e.g., the programming required to display an article should be separated from how that article looks (stylistically) on the screen.

Object-Oriented Programming

PHP helps the design process by supporting object-oriented programming (OOP).

When putting together our system, there are certain chunks of programming that are needed again and again, such as database access, user authentication, etc.

To keep this code neat and tidy, we bundle it together in PHP files called “classes.” We can then create instances (or “objects”) of these classes whenever they are needed.

Thus, the class can be thought of as a blueprint for one or more instances.

For example, we could create a class with code for connecting to a database, and then create an instance of that class whenever we need to query the database.

If this isn’t immediately clear then don’t worry, it will become more obvious when we start coding.

This method of programming allows a complex system to be broken down into smaller and simpler blocks, which makes life easier when it comes to management, modification, and error finding.

Let’s now consider how the system will fit together. This will doubtless be tweaked as you consider the requirements for your own system, but below is a basic outline:

System Diagram

We have four main PHP modules (or “classes”) that will be widely used in the system.

These are tasked with accessing the database, allowing the user to upload files to the site, reading and writing templates, and logging users in and out.

These classes all “extend” one parent class called “systemObject.”

Think of these four as being independent of one another, yet all inheriting whatever data we put in systemObject.

This technique of hierarchy allows us to make changes effecting all four system classes, just by adding or modifying the code in the systemObject parent class.

Again, this concept will become clearer when we start coding. In the middle of the diagram are the basic areas of the administration system, and each will need one or more PHP pages to perform the required tasks.

Join me next month, when we’ll start implementing the most important classes for the content management mystem.

In the mean time, you may wish to familiarize yourself with object-oriented PHP programming, and consider the requirements for your own intranet site.

Stay on top of the latest technology trends — delivered directly to your inbox, free!

Subscription Form Posts

Don't worry, we don't spam

Written by Bobby

Bobby Lawson is a seasoned technology writer with over a decade of experience in the industry. He has written extensively on topics such as cybersecurity, cloud computing, and data analytics. His articles have been featured in several prominent publications, and he is known for his ability to distill complex technical concepts into easily digestible content.