在 Symfony 的控制器中获取 PHP 页面响应
Get PHP page response in controller in Symfony
在 symfony 中,
我有一页,给了一些字符串。
第url页:
"localhost/project/rest1.php" ==>this page gives "444-556-666".
现在我想在控制器中调用此页面并在某个变量中获取该字符串。
/**
* @Route("/ws/checkout/{param}",defaults = {"param"=""},requirements={"param"=".+"})
* @Template()
*/
public function checkoutAction($param){
**// want that php page response here**
}
使用file_get_contents()
$output = file_get_contents("http://127.0.0.1/project/rest1.php");
将您的控制器更改为以下内容
use Symfony\Component\HttpFoundation\Request;
public function checkoutAction($param, Request $request){
$response = file_get_contents($request->getHost() . '/project/rest1.php');
}
在 symfony 中,
我有一页,给了一些字符串。
第url页:
"localhost/project/rest1.php" ==>this page gives "444-556-666".
现在我想在控制器中调用此页面并在某个变量中获取该字符串。
/**
* @Route("/ws/checkout/{param}",defaults = {"param"=""},requirements={"param"=".+"})
* @Template()
*/
public function checkoutAction($param){
**// want that php page response here**
}
使用file_get_contents()
$output = file_get_contents("http://127.0.0.1/project/rest1.php");
将您的控制器更改为以下内容
use Symfony\Component\HttpFoundation\Request;
public function checkoutAction($param, Request $request){
$response = file_get_contents($request->getHost() . '/project/rest1.php');
}