使用json编码从url中的视图'header'发送数据,但该值未传递给变量并在控制器'user'中显示空值 这是代码
'标题'(视图)
<?php foreach ($data as $key ):?>
<?php echo anchor('user/dashboard/?data='.json_encode($key) ,'Home'); ?><span class="sr-only">(current)</span></li>
现在是控制器'用户'
$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);
现在当它进入控制器时显示错误
http://localhost/P_Display/user/dashboard/?data={
数组中没有值
答案 0 :(得分:0)
查看源文档。链接没问题但格式不好html:
<a href="user/dashboard/?data="key3"">Home</a>
您必须使用urlencode:
foreach ($data as $key=>$value ) {
echo anchor('user/dashboard/?data='.urlencode(json_encode($key)),'Home');
}
和
$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);
或者您可以使用序列化(php)。
:)