I'm currently working on a project that need file_get_contents
function. the problem I have right now is: how do I retrieve back the result i got from the file_get_contents
url?
controller
public function send()
{
$pokemon = $this->input->post('username');
$password = $this->input->post('password');
$siteaddressAPI = "http://host/wmc/receive/".$pokemon."/".$password."";
$homepage = json_decode(file_get_contents($siteaddressAPI));
if (! $homepage) {
echo "failed";
} else {
echo $homepage;
}
}
this is the code from file_get_contents controller
function receive($pokemon,$password)
{
$this->load->model('m_wmc');
//echo $pokemon .' - '. $password;
$data= $this->m_wmc->get_member_data($pokemon,$password);
$this->load->view('vw_wmc_bio',$data);
}
The question is how do I return the result of the receive function from the host to display the whole package including the view ?
I managed to display the result from the query. Using this approach.
$this->load->model('m_wmc');
//echo $pokemon .' - '. $password;
$data= $this->m_wmc->get_member_data($pokemon,$password);
foreach ($data->result() as $key) {
echo 'CUSTOMERID' . ':' . $key->CUSTOMERID;
echo 'CUSTOMER' . ':' . $key->CUSTOMER;
echo 'EMAIL' . ':' . $key->EMAIL;
echo 'ADDRESS' . ':' . $key->ADDRESS;
echo 'TELEPHONE' . ':' . $key->TELEPHONE;
}
As per my understanding of your issue, you want to return the view content with your data.So you can simply achieve it by returning your data through view by passing an additional third parameter TRUE
as follows :
$content = $this->load->view('vw_wmc_bio',$data, true);
return $content;
It will return you your view data as a string and you can further manipulate it as per your requirements. I hope it'll help you..!!
If you want to get data in json format, you should return like that from receive function.
public function receive($pokemon,$password)
{
$this->load->model('m_wmc');
//echo $pokemon .' - '. $password;
$data= $this->m_wmc->get_member_data($pokemon,$password)->result_array();
$jsonData = json_encode($data);
header("Content-Length: ". sizeOf($jsonData));
header("Content-Type: application/json");
echo $jsonData;
}
In your send function,
public function send()
{
$pokemon = $this->input->post('username');
$password = $this->input->post('password');
$siteaddressAPI = "http://host/wmc/receive/".$pokemon."/".$password."";
$homepageData = json_decode(file_get_contents($siteaddressAPI));
$homepage = $this->load->view('vw_wmc_bio', $homepageData, true);
if (! $homepage) {
echo "failed";
} else {
echo $homepage;
}
}