Php-mvc Mode (1)

Source: Internet
Author: User
When it's time to learn PHP, it's not difficult to find out how to actually do some single function modules. But a system often has a lot of modules tangled together, when we actually develop it, we will find a lot of code redundancy, call up is not convenient. And the more you write the more the more you feel more and more confused, and finally mess.

So, think about whether you can build a way to call these modules on these modules. If you want to implement what function directly call the corresponding module, do not consider the specific implementation.

Therefore, the upper level release instructions, the lower level concrete implementation. This way of thinking is clear, the problem is not so complicated. A clear division of labor is the trend of the times, but also the trend of code.

Patterns and frameworks are such a wisdom.

Now, I began to follow the footsteps of my predecessors and embark on a journey of MVC design patterns, documenting the experiences and experiences of these days.

First of all thanks to the Pengcheng great God's tutorial, the code is from him, I just talk about my own experience.

MVC design Pattern:

M->model V->veiw C->controll

Model is responsible for the processing of data

Here is the simple processing, directly return a string of STR as a data processing it ~

View is responsible for presenting to the client

View received data $data and output to the foreground, in order to be simple, directly echo ~

Controll is responsible for the overall control of model and view behavior.


Controll, generates a model object and calls the method that gets the data to generate the View object and invoke the output data

Everything is ready, only owe call. Next, create a new PHP call Controller Controll's Show method to test:

Operation Result:

At the end of the first phase of the ~MVC is not so mysterious and difficult to understand, step by step slowly untie its veil

  • 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.