I want to use a good mvc naming convention for a forum im creating.
I wonder, should I use this structure:
controller: threads
model: threads_model (eg. $threads_model->get_all_threads, $threads_model->add_thread, $threads_model->add_post, $threads_model->add_comment)
controller: tags
model: tags_model (eg. $tags_model->get_all_tags, $tags_model->add_tag)
controller: users
model: users_model (eg. $users_model->get_all_users, $users_model->add_user)
or
controller: content
model: content_model (eg. $content_model->get_all_tags, $content_model->get_all threads...)
controller: users
model: users_model (eg. $users_model->get_all_users, $users_model->add_user)
this is my first time using mvc so I want to know what is best practice for this. should i like in the first example separate every “thing” (tags, threads, users…) or should I use the second one? further more, should i in the first example separate comments and posts as well so they will be their own controllers/models?
would be good if someone gave me some good mvc pattern for forums.
Over the 2 you have posted, id say the 1st structure is best. Think about your system as separate entities, and the relations between them. As a simple example
In this case som appropriate associations would be..
Once the associations are made its a bit clearer to think of the methods needed, such as:
There would obviously be more methods for example in the user model you may want to return a particular thread by an id so you would also have a GetThread method that you would pass an id.
Hope this gets you thinking a bit!
One further point is that in your models, such as your Tag model, you have a method addTag, as far as i am aware, you wouldn’t really want this method in your model, as then it could only be called by a tag. If you had to create a tag to add a tag you’d get pretty stuck. Id move this into the controller.