My understanding is that when building an MVC component for joomla we should keep the custom functions in the controller PHP file for that view. I was quickly building up a view on a component and have the following function working in the view to find the shortest distance between two points:
function distance($a, $b)
{
list($lat1, $lon1) = $a;
list($lat2, $lon2) = $b;
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
return $miles;
}
I am then using other variable based information later in the view to call this function:
$distances = array_map(function($items) use($ref) {
$a = array_slice($items, 0);
return distance($a, $ref);
}, $items);
asort($distances);
When I moved the distance function into the controller file I am getting the following error when I try to load the view:
Fatal error: Call to undefined function distance()
What should I change in the call or otherwise to properly format the function for the MVC architecture?