johnmerlino Posted March 18, 2011 Share Posted March 18, 2011 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 More sharing options...
gizmola Posted March 21, 2011 Share Posted March 21, 2011 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. Link to comment https://forums.phpfreaks.com/topic/231045-database-design-with-mvc-framework/#findComment-1190564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.