|
|
|
|
|
|
|
|
Creating a PHP-Based Content Management System, Part 2
Peter Zeidman 8/5/2004 Go to page: 1 2
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:
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 } ?> 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||
Intranet Journal's Tutorials |
|
Managing Editor |