CodeIgniter Forums
Just a stupid question about include() in a view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Just a stupid question about include() in a view (/showthread.php?tid=30787)



Just a stupid question about include() in a view - El Forum - 05-26-2010

[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.


Just a stupid question about include() in a view - El Forum - 05-26-2010

[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'); ?>
 
 
 


Just a stupid question about include() in a view - El Forum - 05-26-2010

[eluser]skunkbad[/eluser]
No, I wasn't using echo. I can reproduce the "1" in the view like this:

Code:
$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".
    $product_display .= include('E:\xampp\htdocs\fastening-systems\application\views\product-includes\velcro\velcro_std_back.php');
}
else
{
     ... ...
}
echo $product_display;



Just a stupid question about include() in a view - El Forum - 05-26-2010

[eluser]danmontgomery[/eluser]
You are using echo.

Code:
$var = 'some_value';
echo $var;

// is identical to

echo '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.


Just a stupid question about include() in a view - El Forum - 05-26-2010

[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