Good MVC practice

Asked

Viewed 323 times

2

I’m starting a project now a bit big, and I chose to use the MVC structure.

I created the entire backoffice base in a folder, but when creating it came to me the following question: Should I create another structure (or copy the current one) at the root to the system front? Or within each folder (models, views, controllers) I must create a folder for the back and another for the front?

As the MVC serves to maintain an organized and class-based system, I saw no advantage in creating two structures, so I would like to know the best practice related to this.

  • 4

    Diego, welcome to Stack Overflow. If possible could [Edit] your question and include the structure you created/want to create? I got a little confused and I didn’t quite get your idea.

  • 2

    When reading the second paragraph I already noticed the confusion. If you arrived at this point, surely you have logical problem. My question is, what do you really know about MVC? If you can describe briefly what you understand about MVC, then we can have a starting point.

  • Friends, I myself realized my logical confusion, rs. As I never used MVC before was stuck the three default folders. But I solved the following, within controllers and models I will create two folders, admin and front. I will create at the root a folder for the admin views and another for the front views. So it solves my problem, because before I thought that to follow the standards I would have to mix the admin files with those of the front in order not to escape from the three default folders. Sorry for the confusion.

1 answer

2

This is Diego speaking, follows a hint of how you can organize your system:

  • Admin

    • Resources
    • controllers
    • models
    • views
  • Portal ( Front )

    • Resources
    • controllers
    • models
    • views

I have worked on some projects, using this structure and it was very practical. For you to have a basis of what structure to adopt, it’s worth giving a check on how market frameworks are doing this.

The above structure is similar to Cakephp’s. http://book.cakephp.org/2.0/en/getting-started/cakephp-folder-structure.html

  • That’s exactly how I’m doing it. I had to make an adaptation in the main class, because by default it accesses the controllers from the root. To open the admin I had to identify by the url, then yes the class knows which controller folder is to access. I could not think of something different yet to identify if it is to open the admin folders or front, but in this my method works. If you have any better it will be of great value, because I am still at the beginning and any modification is quiet for now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.