Some time ago, after I finished php,html,mysql,javascript some basic stuff, I was here to ask the Web and PHP implementations to cross,
That is, the front desk and the background separately write how to get.
Someone told me to use the MVC that someone told me to use Ajax,
Then I self-taught Ajax, and then the general simple will also get the.
I saw the MVC thinkphp tutorial yesterday, after watching three episodes of tutorial, found that actually a lot of things, seemingly with Ajax more simple: and Ajax can be submitted to multiple *.php files, based on the client's different action events real-time feedback results.
I ask MVC, do I have to learn? Where is his real purpose?
Hope to talk to me about it, give an example of what, I am not in the IT industry, I work in a slaughterhouse, if said too professional terminology, I also do not understand, I hope everyone said simple meaning shocking, give an example to say Bai. Thanks, man.
Reply content:
Some time ago, after I finished php,html,mysql,javascript some basic stuff, I was here to ask the Web and PHP implementations to cross,
That is, the front desk and the background separately write how to get.
Someone told me to use the MVC that someone told me to use Ajax,
Then I self-taught Ajax, and then the general simple will also get the.
I saw the MVC thinkphp tutorial yesterday, after watching three episodes of tutorial, found that actually a lot of things, seemingly with Ajax more simple: and Ajax can be submitted to multiple *.php files, based on the client's different action events real-time feedback results.
I ask MVC, do I have to learn? Where is his real purpose?
Hope to talk to me about it, give an example of what, I am not in the IT industry, I work in a slaughterhouse, if said too professional terminology, I also do not understand, I hope everyone said simple meaning shocking, give an example to say Bai. Thanks, man.
These two things do not matter at all, the beginner thinks that MVC is an architectural way, but in fact I personally think this is a kind of thought. My understanding is this:
For any interaction, it can be simplified to a three-step process, i.e.
1-The visitor initiates a request to the server, and the server recognizes that the request is valid (as you went to the front of the room to find xxx, the front may tell you that there is no such person)
2-processing for a valid request
3-Feedback The processing results to the visitor
Where the validity of the recognition request, if effective processing is part of the controller, and the specific process is the model, the results of the final feedback usually need a more friendly effect, that is V (so one argument is to return the JSON directly does not need V, another is to format the data as JSON is also a V application)
This idea is consistent with iteration, for example, for a function, the name of the function is C, and the process is M,return v.
What are the benefits of understanding the idea?
For example SEO optimization, is the adjustment to C, the rest is unaffected
such as business logic changes, is the adjustment to M, the rest is unaffected
For example UI improvement, is the adjustment to V, the rest is unaffected
In combination with the iterative thought mentioned earlier, code written based on generalized MVC has better maintainability, such as:
class User { public function save(array $data) { $this->_valid($data); $id = $this->_save($data); return $this->find($id); } protected function _valid(array $data) { //... } protected function _save(array $data) { //... } public function find(int $id) { $data = ...; return $this->_formatData($data); } protected function _formatData(array $data) { //... return $data; }}
M-Model, V-View, C-Controller
Ajax is requesting the C controller to interact with the front and back of the data in the V view
All have to study hard.
By the way, now the slaughterhouse also want Internet information?
I was a beginner to the concept of MVC is quite vague, but to find an internship generally ask: what is MVC? How do you understand MVC?
Helpless, can only back down: M is the model, for data processing, V is to try to view, for the display page, C is controller controllers, for logic processing ...
After working for a period of time, the application of MVC has a little simple cognition.
We write a page to output a sentence: ' Good good study,day day up! ', then we can create a new index.php file that reads:
Document
In this way, our purpose is fulfilled, and here we need the so-called MVC? No need!
But if we need to do a site with a lot of features, what do we do, also like a PHP file that corresponds to all the features of a Web page?
At this point, we need to do a technical separation of this (MVC):
If there is a page: LOCALHOST/ARTICLE/5, the role of this page is to display the ID 5 of the article related content, then, in C (Control layer Controller), we need to implement the logical processing of this request, then the request logic is:
/*第一步:获取到文章的id,$id = $_GET['article'];第二步:获取文章内容,M->get('article',$id);第三步:展示文章内容,show($data)*/
The function of M (model) layer is data processing, then we can do some data query processing in the M-Layer connection database, and then call the M layer method in C layer to get the data we need, then show it!
V (try to view) layer is the role of the display page, we receive the M layer in the C layer of processed data, and then this data through the V layer of some methods to show to the template in the specified location, and then show to the browser!
That looks like a real hassle!
But think carefully, if in a large project, there is no reasonable structure constraints, all is chaotic code, then how do we maintain? And a project is usually a multi-person cooperative development, if it is a chaotic code structure, then how to cooperate?
There's no time, just write this, and you'll see.
Whether it's MVC or MMVC, and so on, these design paradigms are ultimately designed to reduce code redundancy and facilitate expansion and maintenance.