Php 获取slimpost请求值
本守则Php 获取slimpost请求值,php,slim,Php,Slim,本守则 $email = $app->request('custom1'); print_r($email); exit; 将给予 Slim_Http_Request Object ( [method:protected] => POST [headers:protected] => Array ( [host] => 192.168.56.101 [connection] => keep-alive [co
$email = $app->request('custom1');
print_r($email);
exit;
将给予
Slim_Http_Request Object
(
[method:protected] => POST
[headers:protected] => Array
(
[host] => 192.168.56.101
[connection] => keep-alive
[content-length] => 26
[cache-control] => no-cache
[origin] => chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
[content-type] => x-www-form-urlencoded
[user-agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
[postman-token] => 046f7635-49fe-5fa9-64f9-934f01b97c05
[accept] => */*
[accept-encoding] => gzip, deflate
[accept-language] => en-US,en;q=0.8
[cookie] => PHPSESSID=4effe7cedc113d0c371c64031cb2f22f; 4effe7cedc113d0c371c64031cb2f22f=DEFAULT%7C0%7C2M3TMlgUx3gTlaarYzHIdD28l8q9FTcNubt55%2BUGpAo%3D%7C7456bf61db3500c8bb7b3bc38082a470ce4a2ad3
)
[additionalHeaders:protected] => Array
(
[0] => content-type
[1] => content-length
[2] => php-auth-user
[3] => php-auth-pw
[4] => auth-type
[5] => x-requested-with
)
[cookies:protected] => Array
(
[PHPSESSID] => 4effe7cedc113d0c371c64031cb2f22f
[4effe7cedc113d0c371c64031cb2f22f] => DEFAULT|0|2M3TMlgUx3gTlaarYzHIdD28l8q9FTcNubt55+UGpAo=|7456bf61db3500c8bb7b3bc38082a470ce4a2ad3
)
[get:protected] => Array
(
[email] => custom1
[listid] => 238497
[apikey] => 928je3fb
)
[post:protected] => Array
(
)
[put:protected] => Array
(
)
[body:protected] => custom1=mike%40example.com
[contentType:protected] => x-www-form-urlencoded
[resource:protected] => /mailchimp
[root:protected] => /index.php
)
我怎样才能让$email
成为这封邮件的价值呢?所以它回来了”mike@example.com“
类似于$app->request->get('custom1')代码>将导致:
Fatal error: Cannot access protected property Slim::$request in /var/www/html/index.php on line 26
编辑:
查看整个对象,您似乎发出了一个POST请求,其正文中的值为custom1。但是,这还没有被解析到POST变量下的请求对象中
您应该能够获得如下原始数据:
$app->request()->getBody()
并将其解析为您的选项。查看内容类型,您需要:
parse_str($app->request()->getBody(), $params)
echo $params['custom1']
旧答案:
尝试:
您需要调用$app->request()
获取请求对象,然后从中获取所需的参数。如果是POST方法,您可以尝试以下方法获取变量:
$app->request->post() // For all
$app->request->post('custom1') // specific variable
我希望它能帮助您您使用的是哪个版本的Slim?
$app->request->post() // For all
$app->request->post('custom1') // specific variable