Problems with mvc and ajax ..

Source: Internet
Author: User
Some time ago, after learning some basic things such as php, html, mysql, and JavaScript, I am here to ask how to interact between the webpage and php, that is, how to separate the frontend and backend. someone told me to use MVC. Someone told me to use ajax. Then I learned ajax by myself. Then, it would be simple... some time ago, after I learned some basic things about php, html, mysql, and JavaScript, I asked the webpage to interact with php,
That is how to separate the frontend and backend.

Someone told me to use MVC. Someone told me to use ajax,

Then I learned ajax by myself, and I will do it easily ..

I read the thinkphp tutorial of mvc yesterday. After reading the three sets of tutorials, I found many things. It seems that ajax is easier to use .., in addition, ajax can be submitted to multiple *. php file, real-time feedback results based on different client action events ..

I asked if mvc still has to be learned? Where is his real purpose?

I hope to tell you something. I am not in the it industry for an instance or something. I work in a slaughterhouse. If it is too technical, I cannot understand it either, I hope you can give me an example .. thank you!

Reply content:

Some time ago, after I learned some basic things about php, html, mysql, and JavaScript, I asked the webpage to interact with php,
That is how to separate the frontend and backend.

Someone told me to use MVC. Someone told me to use ajax,

Then I learned ajax by myself, and I will do it easily ..

I read the thinkphp tutorial of mvc yesterday. After reading the three sets of tutorials, I found many things. It seems that ajax is easier to use .., in addition, ajax can be submitted to multiple *. php file, real-time feedback results based on different client action events ..

I asked if mvc still has to be learned? Where is his real purpose?

I hope to tell you something. I am not in the it industry for an instance or something. I work in a slaughterhouse. If it is too technical, I cannot understand it either, I hope you can give me an example .. thank you!

There is no relationship between the two things. Beginners think that MVC is an architectural method, but I personally think it is an idea. My understanding is as follows:
Any interaction can be simplified to a three-step process, that is
1-when a visitor initiates a request to the server, the server identifies whether the request is valid (just as if you go to the data transmission room and ask for xxx, the data transmission room may tell you that this person is absent)
2-process valid requests
3-feedback handling results to visitors
Identify the request validity. If the request is valid, the processing is part of the controller, and the specific processing process is a model. The final feedback results usually require more friendly results, it is V (so one way is to directly return json without v, and the other is to format the data as json is also an application of v)
This idea is consistent with iteration. For example, for a function, the function name is C, the processing process is M, and the return is V.

What are the benefits of understanding this idea?
For example, SEO optimization is to adjust C, and the rest are not affected
For example, a business logic change changes M, and the rest are not affected.
For example, the UI improvement is to adjust V, and the rest are not affected.
Combined with the previous iteration ideas, code written based on broad MVC has better maintainability, such:

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 requests the C controller to perform data interaction between the front and back ends in the V view.
You must study hard.
By the way, is Internet informatization required for slaughterhouses?

I used to describe the concept of MVC at the beginning, but when I look for an internship, I usually ask: What is MVC? How do you understand MVC?
Helpless, it can only be memorized: M is a model for data processing, V is an attempt to view, used to display the page, C is a controller for logical processing...
Later, after working for a while, I learned a little bit about MVC applications.
Let's write a page to output a sentence: 'Good good study, day up! ', So we can create a new index. php file, which is written as follows:

    
      Document    
  

In this way, our goal is achieved. Do we need the so-called MVC here? No!
However, if we need to build a website with many functions, what should we do? a php file like this corresponds to implementing all the functions of a website page?
At this time, we need to perform a technical separation (MVC) for this ):
Assume that there is a page: localhost/article/5, which is used to display the article content with the id of 5. In C (control layer Controller, we need to implement the logic processing of this request. What is the logic of the request:

/* Step 1: GET the article id, $ id = $ _ get ['Article']; Step 2: GET the article content, M-> get ('Article ', $ id); Step 3: show the article content, show ($ data )*/

The role of the M (model) layer is data processing, so we can connect to the database at the M layer for some data query processing, then, call the M-layer method on the C-layer to obtain the required data and display it!
The V (trying to view) layer is used to display pages. We receive processed data from the M layer on the C layer, then, the data is displayed in the specified position in the attempt template through some methods in the V layer, and then displayed in the browser!

It looks so troublesome!
But think about it. If there is no reasonable structure constraint in a large project and it is all chaotic and unordered code, how can we maintain it in the future? In addition, a project is usually developed by multiple people. If the code structure is messy, how can we work together?

There is no time. Write this first and you will see it later.

Whether it's mvc or mmvc, the ultimate goal of these design models isReduces code redundancy to facilitate expansion and maintenance.

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.