PHP MVC Framework Routing Learning notes, MVC Framework Routing Learning Notes _php tutorial

Source: Internet
Author: User
Tags php web development

PHP MVC Framework Routing Learning notes, MVC Framework Routing Learning Notes


Referring to the PHP development of the web, nature is inseparable from the development framework, the development framework provides us with a flexible way to develop, MVC layer separation, business decoupling, etc...

First of all, let's talk about the MVC framework's routing capabilities ...

General single-entry frame routing is the same structure:

Domain/index.php/classname/functionname/var1/var2

The index.php here is called the entry file ... For the server, you only have access to the controller and the methods inside the index.php, and even the values are implemented within the framework based on the PHP level.

Talk was cheap, show you the code!!

First of all, build the following file structure first

Let's try it out, how to access the files inside the controllers ...

Enter the following in the index.php

Print_r ($_server);

Then visit the following address to try it.

Yourdomain/index.php/class/function/var1

Here the author I am using the local environment, I visited the address is localhost/mvc/index.php/class/function/var1

I'm sticking out the 2 most important variables.

[Request_uri] =/mvc/index.php/class/function/var1
[Script_name] =/mvc/index.php

In fact, the basic principle of routing is here:

Through these 2 variables to extract the URL address of class and function, parameters, etc., and then the class include in, through the PHP callback function Call_user_func_array call the corresponding function and pass the corresponding parameters.

The next code, read the code should be more understandable than I write. haha ~ ~

The contents of index.php are as follows

Add the following 2 files to the Application/controllers

Index.php used as the default controller

<?php class Index {function welcome () {echo ' I am default controller ';}}?> hello.php<?php class Hello {publ IC function Index () {echo ' Hello World ',} public Function name ($name) {echo ' hello '. $name;}} ?>

Test it and see if you can access it. Based on the routing structure above. Let's try.

This access is normal, correctly called the "Hello" class inside the name method, and then pass the parameter Barbery passed ...

Try not to enter function name and see if you can call index by default:

The answer is yes ...

Last one, visit the root address to see

Also correctly mapped to the default controller ...

OK, a simple MVC routing function is complete ...

Articles you may be interested in:

    • CodeIgniter PHP MVC Framework China website
    • Mayfish Development Framework for PHP's MVC architecture
    • PHP builds your own MVC framework
    • Smarty usage Instructions for the MVC framework based on PHP web development
    • PHP's MVC pattern Implementation Principle analysis (a simple example of an MVC framework)
    • PHP implementation of the simplest MVC Framework Example Tutorial

http://www.bkjia.com/PHPjc/1105375.html www.bkjia.com true http://www.bkjia.com/PHPjc/1105375.html techarticle PHP MVC Framework Routing Learning notes, MVC Framework Routing Learning notes refer to PHP development web, naturally inseparable from the development framework, the development framework provides us with a flexible development approach, MVC layer separation, ...

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