PHP Learning Notes (4) _php tutorial

Source: Internet
Author: User
Implementing a so-called MVC framework in PHP is straightforward. Let's talk about ideas here.

First, the Spl_autoload_register function is used to implement its own type automatic loading mechanism. So no other code needs to think about how to include the file containing the class.

Second, the name of the Controller and action are extracted from the URL, organized to instantiate the controllers class with reflection, and invoke the controller's Execute method. The controller's Execute method also uses reflection to find the action method and invoke it, writing the response object returned by the action to the output stream. Returns a 404 state if the Controller or action does not exist.

To implement a view, you first define a view class that includes another PHP view file in a method that restricts the scope of the variables in the included file. Second, the view class will have a $model attribute that is used to share the data model with the included PHP so that we can easily present the data in the view. Of course, you can also use Ob_start, ob_get_contents, Ob_end_clean these functions to "capture" the content rendered by the view.

Second step, if you want to render a view, then return a viewresponse in the action, want to output a piece of JSON data, return a jsonresponse, the framework provides a base class Actionresponse, Whatever its derived class is, the framework simply writes its generated content to the output.

You need to be aware of the security and performance issues when you actually use them.

http://www.bkjia.com/PHPjc/748241.html www.bkjia.com true http://www.bkjia.com/PHPjc/748241.html techarticle implementing a so-called MVC framework in PHP is straightforward. Let's talk about ideas here. First, the Spl_autoload_register function is used to implement its own type automatic loading mechanism. So the other code is ...

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