Welcome Guest, Not a member yet? Register   Sign In
Can't Access Variable in View from my Controller
#1

[eluser]Unknown[/eluser]
Hi everyone,

Here's what my controller looks like:
Code:
<?php

class Site extends CI_Controller {
    
    var $file;
    var $path;
    
    function Site() {
        parent::__construct();
        $this->load->helper('file');
        $this->load->helper('directory');
        $this->load->helper('url');
        $this->load->helper('download');
        $this->file = "application/files_saved/hello.txt";
        $this->path = "application/files_saved";
    }
    
    function display() {
        $this->load->view('files');
    }

}

and in my view I just have this:
Code:
<div id="files">
        &lt;?php print_r($file); ?&gt;
    </div>

Now when I go to /site/display I get an undefined variable: 'file' error. Any ideas?
#2

[eluser]LuckyFella73[/eluser]
Should be:
Code:
&lt;?php
print_r($this->file);

// instead of
print_r($file);
?&gt;
#3

[eluser]Unknown[/eluser]
Ah, thanks Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB