duangu8264 2011-07-13 03:08
浏览 22

Cakephp从另一个函数变量继承控制器变量的函数

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 flightPlanCoordinates'.$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++;   
    }
}
  • 写回答

2条回答 默认 最新

  • dongren2128 2011-07-13 03:20
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥20 C# TCP服务端,客户端退出后,不断有数据进来
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?