Just a stupid question about include() in a view |
[eluser]skunkbad[/eluser]
I, for some strange reason, decided to try to use include() to bring in some content into a view. There was nothing special about this content, just plain html, but it was in a php file. The html was inserted as it should be, but in the generated code, there was always a "1" immediately following it. What was happening here? I ended up using a nested view in the end, and yes this is CI so I should have done that in the first place, but I was just curious what was causing the "1" to display.
[eluser]John_Betong[/eluser]
What was the actual call that you used? Did you precede the call with echo? I use it all the time with no problems: Code: <?php include('_content_top.php'); ?>
[eluser]skunkbad[/eluser]
No, I wasn't using echo. I can reproduce the "1" in the view like this: Code: $product_display = '';
[eluser]danmontgomery[/eluser]
You are using echo. Code: $var = 'some_value'; include() doesn't return the content of the file you include. If you want to return the content into a variable, use output buffering or file_get_contents.
[eluser]John_Betong[/eluser]
Try this: [php] $product_display = ''; if(isset($special_display)) { $product_display .= $special_display; // the line below causes the "1", while the line above is the nested view loaded by the controller and does not cause "1". echo __LINE__; $product_display .= include('E:\xampp\htdocs\fastening-systems\application\views\product-includes\velcro\velcro_std_back.php'); echo __LINE__; } else { ... ... } echo __LINE__; // old code // echo $product_display; // new code $product_display; echo __LINE__; die(); [php] edit: problem with line feeds |
Welcome Guest, Not a member yet? Register Sign In |