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.

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

报告相同问题?

悬赏问题

  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead
  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数