【发布时间】:2013-03-03 10:46:34
【问题描述】:
我有一个文件文本文件,我通过 file_put_contents 在其中保存用户 ID 我想在将其发送到查看功能之前显示该用户 ID 这是我的代码 我尝试自己bt没有得到结果....
$name = $this->session->userdata('name');
$id = $this->session->userdata('id');
file_put_contents($filename,json_encode(array('id'=>$id,'name'=>$name)));
$response = array();
$response = json_decode(file_get_contents($filename));
if ($response->name==1){
echo $this->session->userdata('name');
}
echo json_encode($response);
这不起作用,我想显示 bt 如果我删除这个 if 条件然后我在视图文件中得到我的结果
if ($response->name==1){
echo $this->session->userdata('name');
}
谢谢....
【问题讨论】:
-
这需要先进行基本调试。什么时候失败?
file_get_contents($filename)首先会返回任何东西吗?如果有,echo json_encode($response);会给你什么? -
又一个错字问题...
-
如果我删除这个 ** if ($response->name==1){ echo $this->session->userdata('name'); }** 然后我得到我想要的结果 bt 如果我不删除然后我不能得到结果并且没有错误显示
-
我只想获取在数组中以“名称”保存的数据
-
在 if 条件下删除 echo 然后检查你是否得到你的结果,如果你得到然后删除 echo 命令并将数据存储到会话中
标签: php codeigniter json