Just a stupid question about include() in a view

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

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

#3
[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;

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

#5
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.