简体   繁体   中英

CodeIgniter load view into array

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM