Alec Sanger
Alec Sanger

Reputation: 4562

MVC organization for a blog

I'm still just getting into MVC, and for my first real project I plan on creating a blog. This will be extremely basic (at least at first). Everything I need is going to be on the same page. Here are the initial features I am shooting for:

Since I'm still new to the MVC structure, I'd like some advice on how it should be organized.

For my models, I figured I should have a post repository and a BlogPost class for the post data which can be used for both the posting and retrieving. I would also need a class for the user.

When it comes to controllers I'm a bit less confident. Should I have a different controller for every type of action? For example, posting should have a controller, retrieving should have a controller, logging in should have a controller, etc?

As for the views, since I really only need a single page, should I only have a single view and have that view output the appropriate content from my controllers?

Just let me know if I'm on the right track, I suppose. If my thought process is way off, please tell me. I've just started working my way through Steven Sanderson's MVC 2 book, but I feel like I need to go out on my own and play between my reading sessions.

Thanks.

Upvotes: 2

Views: 205

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

Controllers should be grouped by functionality. You could also have a controller per resource (REST). You could have an AuthenticationController which handles authentication and PostsController which will handle the posts retrieval and adding a new post. As far as the views are concerned assuming you will have a single page that will list posts and add new posts you could have a single view but maybe with multiple partial views/editor/display templates.

Upvotes: 2

Related Questions