Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2011, 12:25 AM   PM User | #1
johnmerlino
Regular Coder

 
Join Date: Oct 2009
Posts: 189
Thanks: 38
Thanked 3 Times in 3 Posts
johnmerlino is an unknown quantity at this point
Database design with MVC framework

Hey all,

I'm using mvc framework, where I use controllers for all my main views, such as home page, about us page, contact, etc. However, all the views contain something in common: the ability to create post, update post, delete post, edit post. So I use one model to handle this corresponding to one table called posts. This table contains all the content of the site. Now on different views, I want to render specific posts that relate to views. Currently my index method for all the controllers call the same find method:

Code:
public static function find($param){
			$self = get_instance(); 
			if($param === '*' || $param === 'all'){
				$resources = $self->db->get('posts');  
 				return $resources->result(); 
			}
			return null;
		}
With this find method, all of my views will render all of the posts. So I am wondering should I create another field in the database called page_id, which corresponds to a controller. So when the user invokes index method of home controller, I pass in an additional parameter like '1' and query the database to select all records where the page_id is equal to 1. Is this effective or is there a better approach to restrict posts that display in a content management system?

Thanks for response.
johnmerlino is offline   Reply With Quote
Old 03-21-2011, 07:47 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,687
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
So your "find" method is returning all posts, and you want to filter posts based on page. In my mind, it's bad design to store in your database a page ID like you're thinking of doing. It's better to filter logically, either before you call "find" or after. It makes sense to me to send arguments to the "find" method to filter the results.

By filtering logically I mean use keywords, not page IDs. This gives you the flexibility to build keyword lists that put the same posts in multiple filter buckets as appropriate.
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Tags
cms, database, mvc

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:46 AM.


Advertisement
Log in to turn off these ads.