如何在Symfony2控制器中获取用户IP地址?
问题描述:
提交表单后,我需要在数据库中存储评论用户的IP地址.
I need to store the IP address of the users who comment, in the database after form submission.
是否有任何symfony2函数来获取IP?还是任何其他获取IP的方式?
Is there any symfony2 function to get the IP? Or any other way to get the IP?
答
您可以使用请求服务获取客户端IP:
You can get the client IP using Request service:
$container->get('request')->getClientIp();