return view data is breaking some line endings |
|||
|---|---|---|---|
| Date: | 06/24/2009 | Severity: | Minor |
| Status: | New | Reporter: | Montuelle |
| Version: | 1.7.0 | ||
| Keywords: | Libraries, Loader Class | ||
Description
I use views to generate structured file format,but not HTML.
In this format (Sage native import) line endings are essential.
I’ve never noticed it but if you use the loader to return view as a string data (as I do for compiling multiple view in one text file), the line endings (0x0D 0x0A) just after the php close tags in view are removed.
I precise my view is really close to the output expected, no loops, nor conditions, just variable replacement.
Apparently this is tied to ob_get_contents way of work : http://bugs.php.net/bug.php?id=43756
Not a php bug, but I do not foud further information on this behavior we don’t get using ob_end_flush()
I put the report to version 1.7.0 but we should have the same on 1.7.1
Code Sample
/** In the library/controller **/
$this->buffer = $this->ci->load->view($this->view_name, $this->data, true);
echo 'from view ' . substr_count($this->buffer, "\r\n") . ' lines';
$unrendered_view = file_get_contents(APPPATH . '/views/' . $this->view_name . '.php');
echo 'from file ' . substr_count($unrendered_view, "\r\n") . ' lines';
/** View file extract, straightforward variabel replacement **/
<?=$no_client;?>
41100000
<?=$civilite;?>
<?=$intitule;?>
<?=$contact;?>
<?=$adresse;?>
<?=$complement;?>
<?=$code_postal;?>
<?=$ville;?>
//The empty lines are mandatory to preserve my file format
Expected Result
from view 73 lines
from file 73 lines
Actual Result
from view 60 lines
from file 73 lines
