We will now allow users to create their own posts and display them in their profile page. Posts will also be the main information displayed by our API.
We need first to generate the Post model. As usual, we will use oil
. Enter the following command line:
php oil generate model post content:varchar[140] user_id:int created_at:int --no-timestamp
The output is as follows:
Creating model: APPPATH/classes/model/post.php Creating migration: APPPATH/migrations/001_create_posts.php
You can see that we used the --no-timestamp
parameter here. It simply prevents the automatic generation of the created_at
and updated_at
columns. Since we can have a lot of posts and the updated_at
column then be useless, we generate the created_at
column manually. As a consequence, we need to specify the CreatedAt
observer ourselves. Open the Post model located at APPPATH/classes/model/post.php
and add the following attribute:
protected static $_observers...