In the php Framework-thinkPHPurl, is the get variable not the $ _ GET [] variable?

Source: Internet
Author: User
When I enable & #039; URL_PARAMS_BIND_TYPE & #039; & amp; gt; 1, the parameter passing mode allows sequential parameter passing, that is, the URL does not write a variable name to access localhostyb1HomeGet... why not? How can I assign a value to $ _ GET [& quot;] in thinkPHP? {Code...} when I enable 'URL _ PARAMS_BIND_TYPE '=> 1, // The parameter passing mode allows sequential parameter passing, that is, the URL does not write the variable name

Access

Http: // localhost/yb1/Home/Get...

Why not?

How can I assign a value to $ _ GET [""] in thinkPHP?

    public function test($id  ,$name )    {        echo $_GET["id"] . "-" . $_GET["name"];    }     

Reply content:

When I enable 'URL _ PARAMS_BIND_TYPE '=> 1, // The parameter passing mode allows sequential parameter passing, that is, the URL does not write the variable name.

Access

Http: // localhost/yb1/Home/Get...

Why not?

How can I assign a value to $ _ GET [""] in thinkPHP?

    public function test($id  ,$name )    {        echo $_GET["id"] . "-" . $_GET["name"];    }     

At this time, the code is needed to explain these magical problems.
Look Down (fromThinkPHPLibraryThinkDispatcher.class.php211 rows ):

$ Depr = C ('URL _ PATHINFO_DEPR '); $ paths = explode ($ depr, trim ($ _ SERVER ['path _ info'], $ depr )); if (! Defined ('bind _ controller') {// Obtain the CONTROLLER if (C ('Controller _ level')> 1) {// CONTROLLER layer $ _ GET [$ varController] = implode ('/', array_slice ($ paths, 0, C ('Controller _ level '))); $ paths = array_slice ($ paths, C ('Controller _ level');} else {$ _ GET [$ varController] = array_shift ($ paths );}} // Obtain the operation if (! Defined ('bind _ action') {$ _ GET [$ varAction] = array_shift ($ paths);} // Parse the remaining URL parameter $ var = array (); if (C ('URL _ PARAMS_BIND ') & 1 = C ('URL _ PARAMS_BIND_TYPE') {// bind the variable $ var = $ paths;} to the URL parameter in sequence ;} else {preg_replace_callback ('/(\ w +) \/([^ \/] +)/', function ($ match) use (& $ var) {$ var [$ match [1] = strip_tags ($ match [2]) ;}, implode ('/', $ paths ));} $ _ GET = array_merge ($ var, $ _ GET );}

In the code, the path information in the url is first cut, that isGetpost/test/2/xxxThis part, and in the previous phase of obtaining the controllerGetpost/testAfter the URL parameter is boundpathsAssign datavarAnd then$_GETArrays are merged. Therefore, only values exist in the $ _ GET array, and keys are not required by the landlord. TP does not know which key you want to bind.

For more information about how to bind, see the code:
Look Down (fromThinkPHPLibraryThinkApp.class.php136 rows ):

Switch ($ _ SERVER ['request _ method']) {case 'Post': $ vars = array_merge ($ _ GET, $ _ POST); break; case 'put ': parse_str (file_get_contents ('php: // input'), $ vars); break; default: $ vars =$ _ GET;} $ params = $ method-> getParameters (); $ paramsBindType = C ('URL _ PARAMS_BIND_TYPE '); foreach ($ params as $ param) {$ name = $ param-> getName (); if (1 = $ paramsBindType &&! Empty ($ vars) {$ args [] = array_shift ($ vars);} elseif (0 ==$ paramsBindType & isset ($ vars [$ name]) {$ args [] = $ vars [$ name];} elseif ($ param-> isdefavaluvalueavailable () {$ args [] = $ param-> getDefaultValue ();} else {E (L ('_ PARAM_ERROR _'). ':'. $ name) ;}// enable the binding parameter filtering mechanism if (C ('URL _ PARAMS_SAFE ') {$ filters = C ('URL _ PARAMS_FILTER ')?: C ('default _ filter'); if ($ filters) {$ filters = explode (',', $ filters); foreach ($ filters as $ FILTER) {$ args = array_map_recursive ($ filter, $ args); // parameter filtering }}array_pai_recursive ($ args, 'think _ filter '); $ method-> invokeArgs ($ module, $ args );

The above is the code for binding parameters.URL_PARAMS_BIND_TYPEIf it is true, it will pop up the path parameters for the function in turn, and then assign values using invokeArgs.

Is it okay?

$_GET['id'] = 1001;$_GET['name'] = 'develop';

Dump ($ _ REQUEST); check whether there must be several parameters before the value, such as/id/23

Example: http: // 192.168.45.3: 8125/home...

array(2) {  ["id"] => string(2) "23"  ["_URL_"] => array(4) {    [0] => string(4) "home"    [1] => string(5) "index"    [2] => string(2) "id"    [3] => string(2) "23"  }}

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.