In this tutorial we will discuss how to create a blog in CakePHP, an MVC framework for PHP. You could follow this tutorial without including the latest Twitter Bootstrap 3 in your Layout/default.ctp, but it will look slightly better if you do.

Model

To set up our model we create a file called Posts.php in our app/Model/ directory:

In the above model we’re setting up a slug for the URL based on the Post title, wrapping p tags around our lead text, and setting a publish_date the first time we save the Post while checking the “Published” checkbox in our edit form.

View

Now we need to create some files to set up our views in the app/View/ directory. We’ll start with the index.ctp file:

Next the view.ctp file to show an individual blog post:

And our add.ctp file for adding new blog posts:

And our edit.ctp file for editing blog posts:

Controller

Next we’ll set up our Controller by creating a PostsController.php file in the app/Controllers/ directory:

Database

You will also need to create a table in your database to store your posts. You can do so by running the following SQL statement:

RSS Feed

To set up an RSS Feed of your posts, create a file at app/View/Posts/rss/index.ctp:

Then add a line to app/Config/routes.php:

The RSS feed will then be available at /posts/index.rss.