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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题