Welcome Guest, Not a member yet? Register   Sign In
Fetching content from file into variable?
#1

[eluser]solid9[/eluser]
Hi guys

I'm trying to fetch the content of a file in view folder
and insert it into variable.

Because my header, footer etc... is in external view file.

Example:
Code:
function login()
{
   $this->$data['header'] = '/views/header.php';
  
   $this->load->view('front_page', $this->data);
}

Please help me correct the code above.

Thanks in advanced.
#2

[eluser]Matt S.[/eluser]
You could just do this instead of loading the header and footer in every view file:

Code:
function login()
{
    $this->load->view('header');
    $this->load->view('front_page');
    $this->load->view('footer');
}
#3

[eluser]solid9[/eluser]
I know that, that is the conventional way.

The problem with that it produces un-necessary files in view folder.

I don't think you understand me.
#4

[eluser]CroNiX[/eluser]
You need to set the 3rd parameter of load::view() to TRUE so it will return the view instead of output it, as described in the user guide.
Code:
$this->$data['header'] = $this->load->view('header', null, TRUE);
#5

[eluser]Matt S.[/eluser]
[quote author="solid9" date="1327292002"]I know that, that is the conventional way.

The problem with that it produces un-necessary files in view folder.

I don't think you understand me.[/quote]

I guess I am confused, because it looked like what you were trying to do. Could you explain or show what is in your "front_page" view?

Also, when loading data into the second parameter of $this->load->view(), you don't need to put it in a class property. Just use a local variable, like so:

Code:
$data['header'] = something...;

$this->load->view('front_page', $data);
#6

[eluser]solid9[/eluser]
@CroNiX

thanks man!

I'll try that.




Theme © iAndrew 2016 - Forum software by © MyBB