Welcome Guest, Not a member yet? Register   Sign In
print file content
#1

[eluser]Qiao[/eluser]
Hi guys!

I want to read file (af.txt near index.php) and echo it content.

controller af.php:
Code:
<?php
class Af extends Controller{
    function Af()
    {
        parent::Controller();
    }

    $this->load->helper('file');

    function index()
    {
        $content = read_file('af.txt');
        $this->load->view('af', $content);
    }
}
?>

view af.php:
Code:
<?=$content?>

The result is a blank page.
What am i doing wrong?
#2

[eluser]rogierb[/eluser]
Is this a typo?
$comtent versus $content
#3

[eluser]Qiao[/eluser]
Yes, it is typo. Corrected it.
But still blank page.

And if I add something static to viewer
<?=$content?>hhhhh
It is also blank. No any errors (so url is right).
#4

[eluser]rogierb[/eluser]
try to use
Code:
$content = read_file(FCPATH.'af.txt');
and add an file_exists() to see if the file exists. If not your path is wrong.
#5

[eluser]Qiao[/eluser]
I found mistakes:

1) $this->load->helper('file'); should be in the function, not out
2) only array should be passed to view, not variable

Code:
function index()
{
    $this->load->helper('file');
    $ar['content'] = read_file('af.txt');
    $this->load->view('af', $ar);
}

That is my first CI script!
#6

[eluser]Qiao[/eluser]
But i am wondering about helpers - why cannot i declare them out of the functions?
It would not be convenient to declare them in every function that use it.




Theme © iAndrew 2016 - Forum software by © MyBB