dpr81047 2016-10-17 05:09
浏览 57

如何使用锚点URL帮助程序在codeigniter中将数组从我的视图发送到控制器?

I have an array that saves the values from a counter and I want to send that array to my controller to open another view.

for example I'm in main_view.php in my views folder... within my main_view.php I have a counter and a array that increase with data when something happens.

$counter = 0;
$arr = array();
foreach($value->result as $val){}
    if($val->somethinghappenedtrue){
        $counter++;
        $arr[] = array('data' => $thethingthathappened);
    }
}
$array_encoded = json_encode($arr);

then in my anchor I have:

anchor('controller/method/'.$array_encoded ,'Counter:: '.$counter, array('title'=>'ARRAY SENT'))

and in my view that I want to open with the anchor i have

controller{
    method($array_encoded){
        $array_decoded = json_decode($array_encoded);
        echo '<pre>';
        print_r($array_decoded);
        echo '</pre>';
        $this->load->view('other_view');
    }
}

but it does not work it gives me:

Severity: NoticeMessage: Undefined variable: $array_encoded

  • 写回答

1条回答 默认 最新

  • dongpo5207 2016-10-17 05:30
    关注

    As can be seen here http://www.codeigniter.com/userguide2/libraries/uri.html I think You will have to use $this->uri->segment(3) to get the value of variable $array_encoded first and then you may now decode it and assign it $array_decoded...but then sending an array via the anchor url is probably not the best of things to do.I dont know the specifics of your codes but have you tried posting it via an hidden input field?

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line