HomePHP Page 2 - Building a Blogger with the Code Igniter PHP Framework
Start building the blogger with two MySQL database tables - PHP
People love to communicate, which may be why one of the most popular web applications you can develop is a blogger. In this six-part series, you'll learn how to develop a blogging application using PHP and the Code Igniter framework. In this first article, we'll create the bare bones structure, with plenty of code samples to help you understand the process.
Since the blog application that I plan to construct will store all of the blog entries and the respective comments on a couple of MySQL tables, the first step will consist of creating these tables.
In this case, the first of these database tables will be called "blogs," and its structure will look similar to this:
As shown above, the "blogs" database table comprises three basic fields: the corresponding ID, defined as the primary key; a title; and finally the text of the blog itself. In addition, you can see that it has already been populated with some trivial data, but this step is completely optional. So if you want to start building the blogger with an empty table, then go ahead and do it.
Now that I have defined the first "blogs" MySQL table, it's time to create another one, which will be used to store the comments about each blog entry. Sounds pretty logical, right? Therefore, here's the empty structure of this brand new table, which not surprisingly is called "blogs_comments." Take a look at it, please:
As you can see, the above table will be utilized for storing the comments on each blog entry. In this case, each comment submitted by a user will include the author and the corresponding text as well. In addition, you may have noticed that this table contains a "blog_id" field. This field will be utilized as a foreign key to link this table with the previous one.
So far, so good. At this stage, I have created two simple MySQL tables that will be employed by the blog application, first for displaying a group of existing blog entries, and then for posting different comments on each of them.
The next step involves defining a controller class. This class will initially be responsible for displaying all of the blog entries stored in the "blogs" MySQL table that you saw before.
The details of this process will be covered in the following section. Therefore, jump forward and read the next few lines.