search

Home  >  Q&A  >  body text

ThinkPhp 5.1 About controller parameter _GET, and get(), param() methods

Use URL: http://www.tp51.com/index/Demo/test/name=peter&sex=male

class Demo extends Controller

{

public function test()

{

dump((new Request())->get()); //Equivalent to dump($_GET);

Output:

'/index/Demo3/test1/name' => string 'peter' (length=5)

'sex' => string 'male' (length=4)

             

                                                                                                                                                                                                                         ##       dump((new Request())->param('name'));                                                                                                                                                                                                                                                                        . /male

}

In addition, the same code can be accessed using the following method:

URL: http://www.tp51. com/index/Demo/test?name=peter&sex=male

Copy code

Output:

array (size=3)

'/index /Demo/test' => string '' (length=0)

'name' => string 'peter' (length=5)

'sex' => string The 'male' (length=4)

param() method outputs correctly.

Please ask the teacher and all the heroes to help guide me. Is there a problem with the parameter setting or the code?
Thanks!


Also, Thinkphp URL passes parameters through / or ? Please provide guidance on the problem.
Many thanks!

In addition, I have not changed the core module and configuration file information of PHP5.1.

麦爸麦爸2336 days ago1366

reply all(2)I'll reply

  • 代码输入中...

    代码输入中...2018-08-02 22:05:43

    Is there something wrong with your link? http://www.tp51.com/index/Demo/test/name=peter&sex=male. Don’t you have to use the ampersand in front of it? Then you can splice & with parameters later.

    reply
    0
  • 麦爸

    Hero, I have used both methods. THINKPHP recommends using / instead of ?. If you use the / method, request info will bring the previous controller, module name, and method. URL: http://www.tp51.com/index/Demo/test/name=peter&sex=male If you use the ? method, the controller, module name, and method will become the first parameter of the request info parameter. URL: http://www.tp51.com/index/Demo/test?name=peter&sex=male I don’t know where the problem is. Is it a configuration problem? After looking at the configuration of the relevant URLs in config/app.php for a long time, I still couldn't find the reason. Please give me some advice, heroes! Please!

    麦爸 · 2018-08-03 06:06:09
  • Cancelreply