ThinkPhp 5.1 About controller parameter _GET, and get(), param() methods
麦爸
麦爸 2018-08-01 07:09:54
0
2
1273

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.

麦爸
麦爸

reply all (1)
代码输入中...

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 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!
    麦爸 author 2018-08-03 06:06:09
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!