Ниже приведен код стороны запроса:
manageproduct. php
public function GetTestProductList(){
$data = array();
$curl = curl_init();
curl_setopt = ($curl, CURLOPT_URL, "localhost/test/admin/index.php?route=api/getProductList");
curl_setopt = ($curl, CURLOPT_POST, 1);
curl_setopt = ($curl, CURLOPT_RETURNTRANSFER, true);
$heaaders[
'Cache-Control : no-cache',
'Content-Type : application/x-www-form-urlencoded; charset=utf-8'
];
curl_setopt = ($curl, CURLOPT_HTTPHEADER,$headers);
$response = curl_exec(curl);
$err = curl_error(curl);
curl_close(curl);
if(err){
echo "cURL Error #:" . $err;
}else{
$data = json_decode($response,true);
}
$this->response->addHeader('Content-Type : application/json');
$this->response->setOutput(json_encode($data));
}
Ниже приведен код "localhost / test / admin / index. php? Route = api / getProductList ", который является стороной ответа
//getProductList.php
public function index(){
$json = array();
$json['products'] = array();
$msg = 'SUCCESS';
$data['products'][] = array(
'success_msg' => $msg
);
$json['products'] = $data['products'];
$this->response->addHeader('Content-Type : application/json');
$this->response->setOutput(json_encode($json));
}
Вывод при запуске" localhost / test / admin / index. php? route = api / getProductList ", вывод: {"products": ["success_msg": "SUCCESS"]}
Но если я запускаю сторону запроса; s url "localhost / test / admin / index. php ? route = api / manageproduct / GetTestProductList ", Выводится вывод: null
Что мне нужно изменить, чтобы получить правильный вывод?