本文介绍了如何在Ratchet WebSockets中访问Guzzle QueryString参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用radchet websocket.我很难从对象变量中获取数据.
Hi I am using radchet websocket. I am getting trouble to get my data from an object variable.
请检查我的代码:
var conn = new WebSocket('ws://localhost:8080?user_id=10&receiver_id=20');
$querystring = $conn->WebSocket->request->getQuery();
print_r($querystring);
输出:
Guzzle\Http\QueryString Object
(
[fieldSeparator:protected] => &
[valueSeparator:protected] => =
[urlEncode:protected] => RFC 3986
[aggregator:protected] =>
[data:protected] => Array
(
[user_id] => 10
[receiver_id] => 20
)
)
上面的代码我想要user_id
和receiver_id
,但是我无法获取.
Above code i want user_id
and receiver_id
but i am unable to get.
我的代码:
echo $querystring->data:protected['user_id'];
echo $querystring->data:protected['receiver_id'];
我已经回应但收到错误消息.请帮助我.
I have echoed but getting error message. Please help me.
如果我将对象转换为数组,则显示的格式不正确.见下文.
If I convert object to array it is not showing proper format. see below.
$array = (array) $querystring;
print_r($array);
输出:
Array
(
[ * fieldSeparator] => &
[ * valueSeparator] => =
[ * urlEncode] => RFC 3986
[ * aggregator] =>
[ * data] => Array
(
[user_id] => 10
[receiver_id] => 20
)
)
推荐答案
Guzzle \ Http \ QueryString 扩展了 Guzzle \ Common \ Collection 应该能够使用Collection的方法:
Guzzle\Http\QueryString extends Guzzle\Common\Collection so you should be able to use Collection's methods:
$user_id = $querystring->get('user_id');
$receiver_id = $querystring->get('receiver_id');
或
$parameters = $querystring->toArray();
$user_id = $parameters['user_id'];
$receiver_id = $parameters['receiver_id'];
这篇关于如何在Ratchet WebSockets中访问Guzzle QueryString参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!