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.php
211 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/xxx
This part, and in the previous phase of obtaining the controllerGetpost/test
After the URL parameter is boundpaths
Assign datavar
And then$_GET
Arrays 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.php
136 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_TYPE
If 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" }}