I am trying to parse data from from API to my view on my website. When I put the script directly to the index , just for test , it return:
array(2)
{
["status"]=> int(1)
["categories"]=> array(2)
{
[0]=> array(2)
{
["id"]=> string(1) "5"
["name"]=> string(19) "Pensionar / Veteran"
}
[1]=> array(2)
{
["id"]=> string(1) "6"
["name"]=> string(14) "Alta categorie"
}
}
}
This is how my model looks like :
public function getPassengerCategories()
{
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api_link");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$parsed_json = curl_exec($ch);
$parsed_json = json_decode($parsed_json, true);
$data = $parsed_json;
return $data;
}
catch (Exception $e) {
return $e->getMessage();
}
}
And my controller looks just like this:
function getPassengerCategories()
{
$this->load->model('Curse_Interne_Model');
$data = $this->Curse_Interne_Model->getPassengerCategories();
foreach($data as $categories)
{
foreach ($categories as $category)
{
$html = $this->load->view("front/search_box.php", array(
'categories' => $category
), true);
echo json_encode(array("status" => 1, "html" => $html));
}
}
}
I try first to check if this array is parsed to the view, and that's how my view looks like:
<?php
$data = array('categories' => $category);
print('<pre>' . print_r($data) . '</pre>');
?>
The problem is that all it returns to the view is the following result:
Array ( [categories] => )
1
Any idea how to resolve this? Thank you !