[英]How to get additional $_GET Parameters in Yii2 when prettyurl is enabled?
how can i get additional $_GET Parameters in Yii2 even when prettyurl is enabled? 即使启用了prettyurl,如何在Yii2中获取其他$ _GET参数?
I need to read some feedback from the redirect Paypal-Link but i cant change the Link-Format on Paypal-Side to fit my Yii2 implementation: 我需要阅读重定向Paypal-Link的一些反馈,但是我无法更改Paypal-Side上的链接格式以适合我的Yii2实现:
http://example.com/controller/action?success=boolean&token=xyz http://example.com/controller/action?success=boolean&token=xyz
Thanks for your help! 谢谢你的帮助!
you can use it 你可以用它
http://www.yiiframework.com/doc-2.0/guide-runtime-requests.html http://www.yiiframework.com/doc-2.0/guide-runtime-requests.html
for eg 例如
if you need to use $_GET['success'] or $_GET['token'] 如果您需要使用$ _GET ['success']或$ _GET ['token']
you must use it: 您必须使用它:
$request = Yii::$app->request;
$get = $request->get();
$success = $request->get('success');
$token= $request->get('token');
I figured out a way: 我想出了一种方法:
$url = parse_url(Yii::$app->request->url);
parse_str($url['query'], $array);
$success = $array['success'];
$token = $array['token'];
but it still doesnt seem like the right Yii2-ish way to solve it. 但它似乎仍然不是解决该问题的正确方法。
http://www.yiiframework.com/doc-2.0/yii-web-urlmanager.html this will help You. http://www.yiiframework.com/doc-2.0/yii-web-urlmanager.html这将对您有所帮助。 you can specify GET POST method for any controller,
您可以为任何控制器指定GET POST方法,
[
'dashboard' => 'site/index',
'POST <controller:\w+>s' => '<controller>/create',
'<controller:\w+>s' => '<controller>/index',
'PUT <controller:\w+>/<id:\d+>' => '<controller>/update',
'DELETE <controller:\w+>/<id:\d+>' => '<controller>/delete',
'<controller:\w+>/<id:\d+>' => '<controller>/view',];
for example 例如
'POST <controller:\w+>/<success:\w+>/<token:\w+>' => '<controller>/update',
Use the Request class. 使用Request类。
http://www.yiiframework.com/doc-2.0/yii-web-request.html http://www.yiiframework.com/doc-2.0/yii-web-request.html
print_r(Yii::$app->request->get());
returns all get variables in an array. 返回数组中的所有get变量。 It's like doing
print_r($_GET);
就像做
print_r($_GET);
in straight php. 在直接的PHP。
If you want a specific $_GET variable you access it as follows: 如果要特定的$ _GET变量,请按以下方式访问它:
Yii::$app->request->get('varName');
In your case it would be: 您的情况是:
$success = Yii::$app->request->get('success');
$token = Yii::$app->request->get('token');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.