Welcome Guest, Not a member yet? Register   Sign In
glitch in load->view usage
#1

[eluser]TWP Marketing[/eluser]
I'm getting a bug that I cannot track down. Three characters are appending to the front of a view segment.

The Controller:
Code:
...
  $this->TWP_model->build_view_content( $data );
  $this->load->view('twp_doc_shell',$data);
...

The model:

Code:
function build_view_content( $data )
{
  $this->update_cart_display( $data );                      <--- THIS is where a view segment is created
  $data['Content'] = $this->load->view( $data['View_Name'], $data, TRUE);
  return TRUE;
}

function update_cart_display( $data )
{
  ... $Cart array is declared and loaded with valid data from the shopping cart, all is good to here
  $data['Cart_Display'] = $this->load->view( 'cart_display', $Cart, TRUE ); <--- HERE is the source of the error
  return TRUE:
}


The view simply echos $Cart_Display as a string of HTML code but it contains these three characters () appended to the front of the string contained in $Cart_Display:

Code:
...
<td style="text-align:center; vertical-align:top">
&lt;?php echo $Cart_Display;?&gt;
</td>
...


This is the output HTML:
Code:
...
<td style="text-align:center; vertical-align:top">
<a href="http://www.twpmarket.ing/index.php/twp/cart">Shopping Cart</a>
<table>
...
</table>
</td>
...
Does anyone know why this is happening? I'm stumped here.
#2

[eluser]grisha[/eluser]
Hello there.

I assume that the first line of 'cart_display' is this one:

Code:
<a href="http://www.twpmarket.ing/index.php/twp/cart">Shopping Cart</a>

If you're using UTF-8 encoding for your source files, try to use UTF-8 without BOM - three first bytes of each file encoded in UTF-8.

Hope that helps.
#3

[eluser]TWP Marketing[/eluser]
Bingo,
That was indeed the problem, thank you!
I patched it with this code in the model
Code:
$data['Cart_Display'] = substr($this->load->view( 'cart_display', $Cart, TRUE ),3);
This strips the 3byte BOM from the string.

Does anyone know if there is a more "elegant" solution to removing the BOM from UTF-8 output from load->view()?
#4

[eluser]grisha[/eluser]
Using substr is not a good solution. I would rather recommend you to set up your editor to use UTF-8 without BOM, and then open the file and just save it again. The same problem can occur in many other places.
#5

[eluser]TWP Marketing[/eluser]
I already did that, Notepad++ 2 allows BOM removal from UTF-8 encoding. However this occurs also when I take RSS downloads from (some) outside sources. My patch fixes them also. I'l have to apply it only where the problem occurs but I can live with that.

It wasnt' clear from my posted code, but the cart_display variable was a generated html stream, not a static file, so opening and closing it with notepad++ isn't applicable...
Thanks for your assist!

[update 4/21] Notepad++ requires use of the 'format/convert' menu option to cause a file to be re-formatted to UTF-8 without BOM (and then it must be saved...). I had a mixture of actual CI view files, which did need to be reformatted without BOM and code generated view CONTENT which did not send the BOM to the server. Hence some of my pages showed the BOM on-screen and some did not.

I reformatted my entire view directory and now the 'patch' above is not needed. In fact it caused problems since it removed code from the reformatted data stream. All is well now, thanks to your assistance!




Theme © iAndrew 2016 - Forum software by © MyBB