I am using cakephp 3 to develop a website. Iam quite new to this. I am trying to retrieve data from the function getSelectedItineraryData() in my ItinerariesController. Here is my controller code:
public function getSelectedItineraryData()
{
$selected_itinerary = @$this->request->data('id');
$locationdata = $this->Itineraries->find('locationdetails', [
'selected_itinerary' => $selected_itinerary
]);
return json_encode($locationdata);
}
This uses a custom finder method located in the model file ItinerariesTable.
public function findLocationdetails(Query $query, array $options)
{
return $this->find()
->distinct(['Intineraries.id'])
->matching('Itineraries', function ($q) use ($options) {
return $q->where(['Itineraries.name IN' => $options['selected_itinerary']]);
});
}
This is the ajax request which makes the call to the controller:
function getwypts(callback){
$.ajax({
url: "/Itineraries/getSelectedItineraryData/" + selected_i,
type: "POST",
data: {
id: selected_i
},
//async: false,
success: function(result, status) {
var dayint = 1;
alert(result);
itins = JSON.parse(result);
var day_arr = JSON.parse(itins.day_array);
var json_day_list = JSON.parse(itins.json_day_data);
$('#temp_dir_array').val(JSON.stringify(day_arr));
$('#sel_id_name').text(itins.name);
start_n = itins.start_name;
end_n = itins.end_name;
var tempp = JSON.parse(itins.day_array);
waypt_obj.start = itins.start;
waypt_obj.end = itins.end;
waypt_obj.waypt = itins.arr_intin;
for (dayint = 0; dayint < json_day_list.length; dayint++) {
temp11 = tempp[dayint];
$("#itin_list").append('<div id="itinerary_item_' + (dayint + 1) + '" value="' + dayint + '"><a href="#" style= "border: 2px solid red;list-style-position: inside; margin: 5px" class="list-group-item testing"><input type="hidden" id="viewport_wp_item" value="' + tempp[dayint][0] + '" ></input><div class="alert alert-success"><b>Day ' + (dayint + 1) + ' of Trip (Overnight stay at ' + json_day_list[dayint].overnight + ')</b></div><div id="" class="alert alert-info"><b>Places Visited: ' + json_day_list[dayint].places + '</b><br>' + json_day_list[dayint].desc + '</div></a></div>');
}
if(callback) {
callback();
}
}
});
}
The issue I have is that this request returns an empty result. It seems that this is because the custom finder methood does not return a correct response. What is wrong in my controller? Or is the error coming from somewhere else? Thanks in advance, been trying for hours on end now.
debug()during different parts of the process to see how far it gets?