SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: CMS Class Structurce
-
Nov 6, 2008, 20:41 #1
- Join Date
- Aug 2006
- Posts
- 46
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
CMS Class Structurce
I've developed a couple Content Management Systems now, but theres one concept I really struggle with, and its how to properly design classes in a CMS situation.
I've tried designing classes, but they never really turn out to be a very efficient way of doing things, and I have a hard time visualizing the proper way to structure the classes.
Given a simple blog CMS (one part of the CMS).... how would I structure the blog class? I have a blog table in the database with the usual fields: ID, Title, Content, Timestamp, User. Whats the most effective way to make this into a class?
I'm using PHP and MySQL, if it helps. Thank you for any ideas you can pass my way.
-
Nov 7, 2008, 19:36 #2
- Join Date
- Feb 2007
- Posts
- 270
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Probably as many ways to do it as there are programmers doing it.
Create a class for the db table. It knows how to create/read/update/delete blog posts. It also knows how to derive any calculated fields you need to use. Basically, it's responsible for delivering an array where the rows are rows of the table and the columns are the fields in the rows (plus any calculated/derived fields) in a form the rest of the code can use.
Then there's a second class that takes the data array above and knows how to format it for the browser.
If you break the above structure into three classes, you get the traditional MVC (Model/View/Controller) architecture, which is probably optimum but may be difficult to insert into your CMS. You could also, if you like, combine the output functions into the first class, but then whatever the output controller is will have to know more details about the class. It breaks encapsulation a bit, and is a bit more complex to maintain, but it works.
-
Nov 10, 2008, 01:38 #3
- Join Date
- Nov 2008
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It depends on how big is your cms application. If big, then use classes, otherwise, you can simply use functions.
If you use class, you can just name the function in your class, for example, blog to add, update, delete, get and if you use function, you will name them add_blog, update_blog, delete_blog, and get_blog.
For smaller website, I would go with just functions.
Bookmarks