Intranet Journal   Earthweb  
Events Jobs Premium Services Media Kit Network Map E-mail Offers Vendor Solutions Webcasts

   Intranet Journal Subjects
Search Earthweb

Privacy Policy



internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

internet commerce
Be a Commerce Partner
















 

[ Home | Discussion Forum | How Do I... | Lotus Notes Intranets | Microsoft SharePoint | Products | Shopping  ]

free news!


Creating a PHP-Based Content Management System, Part 2


Peter Zeidman
8/5/2004

Go to page: 1 2 

Printer Friendly Version

Have a question about this article, object-oriented programming, or PHP? Visit Intranet Journal's Discussion Forum

Last month I laid out the structure of a content management system (CMS), to be written in PHP for use on a Web site or intranet. This month we'll get going on writing the most basic code on which it will rely.

This article requires a basic knowledge of PHP programming, although a number of concepts are explained for those less experienced.

Our CMS will be stored in a number of folders, structured as follows:


 cmsadmin
 includes  templates  images
 (The admin area of the Intranet)  (The PHP code that will be included in a number of different pages)  (Templates for pages on the Intranet)  (Pictures that will appear on the Intranet)

You may wish to create these four folders now. We're going to start by creating the PHP class which all others will "extend." This will be the root of the administration system, and anything we put in it (such as variables and functions) will trickle down to the other classes.

This root class will be called 'SystemComponent'. The code follows, and a full explanation is below:

<?php
class SystemComponent {

var $settings;

function getSettings() {

// System variables
$settings['siteDir'] = '/path/to/your/intranet/';

// Database variables
$settings['dbhost'] = 'hostname';
$settings['dbusername'] = 'dbuser';
$settings['dbpassword'] = 'dbpass';
$settings['dbname'] = 'mydb';

return $settings;

}

}
?>

Reminder: A class is a block of code. Whenever we need to run that code, we create an 'object' or 'instance' of the class. We can create as many instances of a class as we like. If you don't understand objects and classes by the end of this article, I recommend getting a book or finding a Web site on Object Oriented Programming.

The above code starts off by telling PHP that our class will be called 'SystemComponent'. Between the braces (squiggly brackets) we declare the variable $settings, and a function called 'getSettings'. The purpose of this is to store a number of values in $settings, containing the path on the server to the intranet ('siteDir'), and the details of the database. Change these appropriately for the database system you'll be using (this tutorial uses MySQL, more details coming up). Finally, the 'return' command sends $settings to whichever class or function has requested it. We'll be storing more data in $settings as the series progresses.

Save this code to a file called SystemComponent.php in the 'includes' folder you created. Now let's do something with this class.

Go to page: 1 2

Printer Friendly Version

Of Interest
Intranet eXchange Discussion Board
Creating a PHP-Based Content Management System, Part 1
PHPBuilder

email this page

Tutorials
and more at:
Intranet Journal's Tutorials
Intranet Journal Favorites

Creating a PHP-Based Content Management System

The Spyware Guide

Introduction to Microsoft SharePoint Portal

Intranet Journal
Part of the EarthWeb Network

Managing Editor
Intranet Journal

Tom Dunlap

EarthWeb Home Page
Jupitermedia Home Page

Media Kit



internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs