Cakephp inheritng controller variable in function from another function variable
is there a way we can get variable from another function for the current function in controller and user set function to use in corresponding view file?
Sorry guys I meant passing view file variable to another view file...Below is the code...
function get_random_color()
{
$c="";
for ($i = 0; $i<6; $i++)
{
$c .= dechex(rand(0,15));
}
return "#$c";
}
$i = 0;//debug($trips);
foreach ($trips as $trip) {
$colour = get_random_color();
$numItems = count($trip['trip']['coords']);
if($numItems > 3){
$x = 0;
echo 'var flightPlanCoordi开发者_开发知识库nates'.$i.' = [';
foreach($trip['trip']['coords'] as $coords) {
if($x+1 == $numItems) {
echo 'new google.maps.LatLng('.$coords['latitude'].','.$coords['longitude'].') ';
}
else {
echo 'new google.maps.LatLng('.$coords['latitude'].','.$coords['longitude'].'), ';
}
$x++;
}
/*
for($x = 0; $x<sizeof($trip['trip']['coords']); $x++) {
echo 'new google.maps.LatLng('.$trip['trip']['coords']['latitude'].','.$trip['trip']['coords']['longitude'].'), ';
}*/
echo ']; ';
echo 'var flightPath'.$i.' = new google.maps.Polyline({
path: flightPlanCoordinates'.$i.',
strokeColor: "'.$colour.'",
strokeOpacity: 1.0,
strokeWeight: 4
});';
echo 'flightPath'.$i.'.setMap(map);';
$i++;
}
}
You can do a requestAction, although it is considered the slower way to get at that data. If you give more details I might be able to give you a better answer.
$this->requestAction('/posts/list');
more on requestActions here: http://book.cakephp.org/view/991/requestAction
Use Configure class if you need a global variable in this situation,request action should be a bad choice.
精彩评论