Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMichael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsI need advice on organizing my classes for a simple blog site
I am building my first site, a blog, using an mvc framework, but I need a bit of advice. I have a few utility classes that I have written that I feel good about, but I also have a Post class and a PostCollection class. What I am wondering is if I should put my createNewPost() method in the Post class or not? The createNewPost() method will connect to the database and add a new post to it. Or should I create another class for this method? I am still trying to understand how to separate out different methods into appropriate classes. Thanks for any advice.
Michael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsHey Pascal thanks very much for the reply and the link, its (somewhat) helpful, though I am using Slim framework and a lot of what's in the Symfrony framework is very foreign to me. Slim doesn't give you the same kind of detailed file structure and separation of different classes into different folders like that, and unfortunately Treehouse does a poor job of explaining this stuff.
Pascal Breitrück
Courses Plus Student 3,206 PointsPascal Breitrück
Courses Plus Student 3,206 PointsHey Michael, good question. I've also been working on the right structure for some time now. I work a lot with Symfony . There I have enties (ORM/Table), repositories (in the repository lives the complete communication with the database . For complex logic I create single service classes .
I would have your createNewPost() in the repository ;D .
Some time ago I found a good answer to the topic model.
https://stackoverflow.com/questions/5863870/how-should-a-model-be-structured-in-mvc
I hope that helps ;D HAPPY CODING