doushuo2834 2015-04-13 08:20
浏览 55
已采纳

CodeIgniter将视图加载到数组中

I'm trying to load a view which contains html elements like div etc into an array, but I'm having trouble doing it. Somehow, even if I replace quotation marks, it seems to be causing error. After loading the view into the array

$tmp =  $this->load->view('details/action_task');
$result['html'] = str_replace('\\"','\\\\"', $tmp);

$resp = json_encode($result);

on chrome console, output is

{"code":1,"html":""}            
            <div class="text-center">Response</div>

As you can see html is empty, and its "should be" value is out of the json object. Any idea on solving this?

  • 写回答

1条回答 默认 最新

  • duanjian4698 2015-04-13 08:24
    关注

    As codeigniter doc provided,

    There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

    Try this ..

    $tmp =  $this->load->view('details/action_task', '', true);
    

    Hope it will be useful for you.

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

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料