Creating and maintain a web site is not a hard job today especially at a time when the full-proof and automated content management systems are so widely available. However, creating a simple CMS is also not much of a tough task. Here is the simplified and step by step guide for first time PHP users for the creation of their first CMS.
Building the Class
In order to lay a foundation for your first content management system, you simply need to build a class in the file named “simpleCMS.php”. Once the class has been created, add four variable namely host, username, password and table. In other words, try to create one class with five methods and four variables. To bring out a cleaner code especially in a project as large as creating an entire CMS, try opting for the PHP’s object oriented approach.
All the four variables created under the class are actually used in connecting the database. $table, $username, $password and $host provide an access and path to the database on the specified server. The database is further constructed through the method buildDB ().
Building the Database
The function buildDB () is always declared as private in to the parent class. Such a function usually runs a MySQL command which further checks the generated database so as to confirm if ‘testDB’ exists. If the performed check is positive, the function would pass on a notification terming “success”. In case the result is negative, it will create a table and will further assign three columns to it in order to hold the unmatched data.
Connect the Database
We have already created a function which will build our table. It’s now time to create one that will connect it to the database. In order to so, we call two functions. The first one being mysql_connect() that will simply hook the database and the other one being mysql_select_db() that will save all the data in the appropriate place. However, the connect () function is used to connect further to the database and run the buildDB () function. Also, you must make sure that you are in no way overwriting the entire database every time you tend to load the page so as to call the specified functions.
Build the Form
Now the database has been created and you need to put relevant stuff into it. Use the form element in order to declare the function. In order to reference the file which is currently in usage, try adding an extra $_SERVER[‘PHP_SELF’] variable in the action attribute of the current form element. This will help in serving as a shortcut and is highly beneficial if you are planning to reuse your code for each page on a different website as it will save the trouble of rewriting.
Saving the Data in the Database
The write () method is employed to save the data in the existing database. Put a variable $p in to the function call which will hold the entire information that has been earlier sent from the form through the past method. Also, make sure that you check all the variables before saving the entire database so that they are not left blank. Once the variables have been set, you should then try to set the variable $ created with the existing Unix Timestamp. This will aid in the sorting of the entries in a chronological manner whenever you will try to view them in future.
Displaying the Information in the Database
In order to get the information back out from the generated database, we make use of the display_public () method. This is indeed one of the most complex methods employed in the creation of simple content management systems. Therefore, you might try and ask for a little savvy help on the same in case you are unable to understand anything.
May 20, 2013 at 2:22 pm
nice article Jack,
nice information about building your own CMS..,
but i don’t think if any body want to start a website have to do the same because there are many CMS in the internet, like WordPress, tumblr etc..
by the nice article from the programming point of view..:)
May 20, 2013 at 7:31 pm
Building own CMS is a good idea, but what is the need t build one, when we have the most brilliant WordPress. One can customize it to it’s very own use. And also it a open source too.
May 21, 2013 at 6:56 am
Nice post and thanks for sharing this post but I totally agree with Myles that why we build CMS when we have wordpress.
May 31, 2013 at 7:54 am
This is a nice tutorial if you want to build a basic, custom CMS. But in most cases it’s not worth the effort because there are a lot of useful, fully customizable CMS on the Internet like WordPress, Joomla etc.
October 24, 2013 at 1:13 pm
It could be easy to build a CMS but i think, it will not be so easy to go on the top in such a competitive time.