We assume that you have a limited knowledge of Phpixie, and you can login (ie: users). You can see how to authenticate and have a user here. You can ignore most of the user code if you prefer to have your blogs editable or postable by anyone.
Creating a blog first means creating the database layer. We will show you a simple, but we feel effective database table based off not just our own knowledge, but what we found available on the web as well.
SQL Table Thoughts:
- It is important to know that int(11), means that the column is an int, and in your sql visual display you will see 11 digits, but the full int will be stored whether this number is bigger or smaller. varchar(255) means that there are 255 characters! This is unlike int(11) which will be size int no matter what.
- We use varchar for the title because of efficiency, please see the following article: http://www.pythian.com/blog/text-vs-varchar/. We expect our titles to be varchar, because no one wants long titles, but you can go up to 65535 letters with varchar.
- We want to have users be able to post blogs, and put their name as the author automatically so we are going to link to their user id. If you assume there might be multiple authors on your blog you will need a one to many relationship, but most blogs are written by one individual, so lets not over-complicate the data structure.
PHPixie is just simpy a GREAT framework to work with, and I think it becomes very obvious when you see the code.
Blog Modal (representing our Blog table):
By naming the table "Blog" it looks for the plural of that model as a table in sql called "blogs". By extending Model we get all the necessary functionality, which means that phpixie will know all about the columns. All we need to do is describe the user relationship. You can specify the table name if you prefer, but for now we have no reason to. "Belongs to" means that there is a user_id key which relates to the user model (a user table) and that the user_id key is equal to the id in the user table. This means simply that a user "owns" this blog. It is easier to understand when you see the code in action.
In case you don't know how to get the data, it is pretty simple:
I didn't just write out all the code or leave it as a download because, I think it is a greate chance for you to take the building blocks and make something awesome. I hope to explain a couple more complicated features to come like comments or tagging.