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).

    :)

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

报告相同问题?

悬赏问题

  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能