dongtai419309 2017-02-08 07:53
浏览 64
已采纳

从foreach向url发送数据以传递codeigniter中的变量

sending data from foreach which is in the view 'header' in the url using json encode but the value is not passing to the variable and showing empty value in the controller 'user' here is the code

'header'(view)

<?php  foreach ($data as $key ):?>

    <?php echo anchor('user/dashboard/?data='.json_encode($key)  ,'Home'); ?><span class="sr-only">(current)</span></li>

now the controller 'user'

$data=json_decode($_GET['data']);
  print_r($data);
  $this->load->model('Pmodel'); 
 $email['data']=$this->Pmodel->select_model($data);

   $this->load->view('dashboard/dashboard',$email);

now when it goes to the controller it shows error

http://localhost/P_Display/user/dashboard/?data={

no value in the array

  • 写回答

1条回答 默认 最新

  • doushi9856 2017-02-08 09:29
    关注

    Look source document. Link is ok but is no good format html:

    <a href="user/dashboard/?data="key3"">Home</a>
    

    You must use urlencode:

    foreach ($data as $key=>$value ) {
        echo anchor('user/dashboard/?data='.urlencode(json_encode($key)),'Home');
    }
    

    And

    $data=json_decode(urldecode($_GET['data']));
    print_r($data);
    $this->load->model('Pmodel'); 
    $email['data']=$this->Pmodel->select_model($data);
    
    $this->load->view('dashboard/dashboard',$email);
    

    Or you can use serialize (php).

    :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备