What we are going to build here is a very simple Content Managed site. The code has been limited to the bare necessities because the purpose is to provide direction rather than a solution.
These instructions have been written using WampServer which runs under the Windows operating system. WampServer is for Windows. There are versions for Linux (Lamp) and Mac (Mamp).
WampServer is a Windows web development environment. It allows you to create web applications with Apache, PHP and the MySQL database. It also comes with PHPMyAdmin to easily manage your databases. Download WampServer
By default, Apache listens to port 80. This is a problem if windows iis is also loaded and using that port. The solution that I use is to change Apache.conf to listen to port 8080. Then my phpMyAdmin url looks like http://localhost:8080/phpmyadmin/. To achieve this find any http.conf files in folders under wamp. Edit them to change the line Listen 80 to Listen 8080.
If you use Skype, there can also be a conflict with port 80. If you have this problem, open Skype, Go to Tools->Options->Advanced Settings Tab->Connection and Uncheck the Ã¯Â¿Â½Use Port 80 and 443 as alternatives for incoming connectionsÃ¯Â¿Â½
Once installed it provides access to an Apache server, MySql database including phpMyAdmin which is an administration tool and PHP. That is all we need to get our site working.
After installation of WampServer you will have a folder called wamp under which, amongst others, will be a folder called www. This is where our site will be stored. We are looking to create a directory structure like this:
It is not my intention to provide a tutorial on object oriented programming (oop). The benefits to be gained from oop are realised when we do more than just move functions into classes. I will leave that discussion to others.
This is not really correct but it may help some. When I say method think function. When I say property think variable.
To explain what is going on here, we need to understand how to create an object from our class and then call its methods and obtain its property values. I will use test_page as our class name as it matches the example. Here goes:
Before we can do anything with a class we need to tell php where to find it using include or require (even better require_once). Because I also want to check if the class already exists and I don't want to have the full path to the class scattered all over my code, I have a function in config.inc.php called includeClass that does the necessary checking and knows how to find the class. Therefore, to include the code is simply a matter of calling includeClass('test_page');
Next we need to create an instance (object) out of our class (instantiate the cass to creata an object). Our class is called test_page. We know that because it starts out with 'class test_page' and then wraps everything else in curly braces. So to create an instance we use $tpo = new test_page();. (I have used $tpo but it could be any properly formed variable name) From now on when we want to access our class methods or properties we use $tpo-> followed by the method or property followed by the arguments required in brackets..
Just one more thing that I want to explain is the use of $this-> in a class. When we are coding a class and we want to refer to another method or property in the same class we do not need to include the code or instantiate the class we merely use $this->.
Here we describe the files in each folder and their purpose. The code is well populated with comments.
maketestdb is a sql script that will:
There are two classes in this folder.
dbconnect.php provides the database connectivity. This is a simplified version which just provides the functionality required. There are many samples of more thorough database access classes available and well explained on the web. The version provided here is aimed at providing the functionality needed for this project rather than a full data access class.
test_page.php is the class that serves the site page content and builds the navigation menu. The methods are quite thoroughly populated with comments. Let's look at what it does.
site.css contains the cascading styles for the site. This is not a css exercise and so the code here is minimal.
Config.inc.php contains some site wide definitions. At present these are only the database connection variables and a function that knows how to include the class files and make sure that they are only included once. If you expand on the site, it is likely that you will want to add other variables to this list. It is useful to have them all conveniently located in the one place.
This is by no means a fully functional cms. However, it may well help to get you started. It has been written to provide a working example of a process that will work and is ready for expansion.
After preparing this example, I had a look on the web for php + Simple CMS. There are several other examples. It was unpleasant to see some of the responses to the one that I read thoroughly.
There were two comments that I enjoyed and I have placed these at the foot of this page with a link
Let me try to avoid such responses.
Basically, here is a small application that will provide a limited degree of functionality. Some may find the process exciting. As I did when I first started working with php and MySQL.
Here, the author was attempting a very similar exercise. building your first simple cms. Many of the comments made appear to have been written to support large egos rather than for any constructive purpose.
Comment: Fur fuck sake, use a framework! I agree that any PHP developer should be able to do this in 5/10 minutes, but come on, why waste time like this? This is why PHP applications grow to be unmaintainable monstrocities of vague undocumented codeÃ¯Â¿Â½
Response: I know, JEEZ, why would you want to LEARN something when itÃ¯Â¿Â½s already done. ThatÃ¯Â¿Â½s why IÃ¯Â¿Â½d never learn to play an instrument, there are already loads of albums already there for me to listen to.
signed: Chris Coyier (author)
NowÃ¯Â¿Â½ No one who works with open source technologies should dare bash another for freely sharing knowledge. Ever. Correct mistakes out of respect for the readers, but donÃ¯Â¿Â½t bash the author. HeÃ¯Â¿Â½s merely trying to contribute to the community. ThatÃ¯Â¿Â½s what open source is all about.
signed: The Smart One
Constructive criticism will be gratefully received and reflected here. Feedback will be moderated.
How To Use