In considering a question, why MVC must model a directory, view a directory ...

Source: Internet
Author: User
Tags php framework tidy
In considering a problem,
Why MVC must model a directory, view a directory, controller a directory,
Instead of following the module, put it in a directory:
such as the Order module:
order/
ordercontroller.php
ordermodel.php
Orderlist.phtml
Orderedit.phtml

I think this is the time to develop the order module,
It doesn't take a while to find the Order folder in the View directory, and then find the edit template.
Find Ordermodel in the model catalogue in a moment.
......

And it's more convenient to move to other projects. Copy the whole folder.

Add a few real benefits:
One, for example, you have newly developed order module to upload to the server, you just need to send the order directory up, and do not need to go to the controller directory to ordercontroller.php, and then to the Model directory ...
Two, such as you sell software, the article Module 1000 block, Order Module 3000 block ... The customer wants what module, only need to send the corresponding module catalogue to him is good, but does not need to transmit a fragmented directory.
Third, this structure is in line with normal thinking, such as composer, such as NPM, are each module has its own directory,

It's like you're going to tidy up your pretty girl. Gallery, you must be put Lin Chi-ling's directory, Cang teacher put a directory,
One day I want to ask you to miss Cang Teacher's picture, you put Cang Teacher's catalogue to me just fine.
And most of the existing PHP framework is the practice of the. JPG no matter whether Lin Chi-ling or Cang teacher put a directory,
Then put a directory in GIF ...
What are the benefits of this sub-structure?

Then take the front-end for reference,
Project small words, or old practice, is CSS a directory, JS a directory, img a directory,
But the bigger project, and the advanced front-end engineer, must be divided by module, not by file type.

Reply content:

In considering a problem,
Why MVC must model a directory, view a directory, controller a directory,
Instead of following the module, put it in a directory:
such as the Order module:
order/
ordercontroller.php
ordermodel.php
Orderlist.phtml
Orderedit.phtml

I think this is the time to develop the order module,
It doesn't take a while to find the Order folder in the View directory, and then find the edit template.
Find Ordermodel in the model catalogue in a moment.
......

And it's more convenient to move to other projects. Copy the whole folder.

Add a few real benefits:
One, for example, you have newly developed order module to upload to the server, you just need to send the order directory up, and do not need to go to the controller directory to ordercontroller.php, and then to the Model directory ...
Two, such as you sell software, the article Module 1000 block, Order Module 3000 block ... The customer wants what module, only need to send the corresponding module catalogue to him is good, but does not need to transmit a fragmented directory.
Third, this structure is in line with normal thinking, such as composer, such as NPM, are each module has its own directory,

It's like you're going to tidy up your pretty girl. Gallery, you must be put Lin Chi-ling's directory, Cang teacher put a directory,
One day I want to ask you to miss Cang Teacher's picture, you put Cang Teacher's catalogue to me just fine.
And most of the existing PHP framework is the practice of the. JPG no matter whether Lin Chi-ling or Cang teacher put a directory,
Then put a directory in GIF ...
What are the benefits of this sub-structure?

Then take the front-end for reference,
Project small words, or old practice, is CSS a directory, JS a directory, img a directory,
But the bigger project, and the advanced front-end engineer, must be divided by module, not by file type.

So the question is, what about the public model, the view fragment, and so on? Can a single folder be copied to another project directly on the work reality? In order to "find the Code", in the code structure, I think it is not economical. The View Model controller can easily jump through the IDE's tracking function, or unified naming, fast search by name is a good way to solve the "Find File Trouble"

Of course, if the business itself is too large to need a similar split, such a split is not entirely unreasonable, but must draw a boundary, clarify the rules of the split, clarify the common module placement and maintenance methods and so on

Well, there's some truth to what you're saying, you split each project into a small app, each app has its own controller model view, and it's good to be very scalable, but isn't a big project that doesn't show the benefits, Huizhoushangpaicopyright Shopping mall Ecstore is the landlord said to do so, divided into a lot of apps, the landlord's thinking is right

For example, order and admin have view is the same.

The call to view and model is not exactly one by one, and when a view calls more than one model, you don't know that the view should be written to that directory.

MVC为什么一定要Model一个目录,View一个目录,Controller一个目录
This sentence is not set up, who rules the mvc need to organize the code structure.

In addition, the main topic of the module, and python the web framework of the django Project Code organization is similar, while flask the Blueprint ( blue_print ) way to organize the code is also worth learning.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.