Jump to content

Recommended Posts

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:

 

public static function find($param){
		$self = get_instance(); 
		if($param === '*' || $param === 'all'){
			$resources = $self->db->get('posts'); //but I can't do self::db - because db is not a static property of the Home class, which is what self is pointing to.
				return $resources->result(); //result() returns the query result as an array of objects whereas result_array() returns the query result as a pure array.
		}
		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.

Link to comment
https://forums.phpfreaks.com/topic/231045-database-design-with-mvc-framework/
Share on other sites

Your posts model should be sophisticated enough that you can pass a parameter that is the equivalent of adding a  WHERE clause to it that limits the result set to just the universe of posts for that section.  This seems like a database design question.

 

Each controller would pass the applicable constant.  There is no value in my opinion to trying to make something generic there.  You have to write a controller and passing the appropriate "posttype" is not going to change once you've written the controller.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.