Welcome Guest, Not a member yet? Register   Sign In
Passing data to view
#5

[eluser]KingSkippus[/eluser]
You're halfway there. You do indeed have to pass an array to the view as you've done in the top snipped of code. The mistake is that within the view, each of the array keys becomes a variable, and each associated value because the contents of the variable.

In short, in the second snipped of code, try this instead:

Code:
echo $text;

You should see "some text" appear on the page. The array variable passed to the view isn't visible, only the keys as variables themselves. To be honest, I actually prefer the syntax that follows, as it avoids declaring "dummy" variables and makes it, in my opinion, a little easier to me to see what's going on:

Code:
$tmp_data['main_content_view'] = $this->load->view('content/profile', array(
    // These are variables that will be available in the view as $text, $another_var, etc.
    'text' => 'some text',
    'another_var' => 'more stuff',
    // ...
    ), TRUE);

But different strokes for different folks I guess, use whatever is easier for you.


Messages In This Thread
Passing data to view - by El Forum - 07-20-2010, 07:03 AM
Passing data to view - by El Forum - 07-20-2010, 07:06 AM
Passing data to view - by El Forum - 07-20-2010, 07:08 AM
Passing data to view - by El Forum - 07-20-2010, 07:09 AM
Passing data to view - by El Forum - 07-20-2010, 07:10 AM
Passing data to view - by El Forum - 07-20-2010, 07:11 AM
Passing data to view - by El Forum - 07-20-2010, 07:15 AM
Passing data to view - by El Forum - 07-20-2010, 07:32 AM
Passing data to view - by El Forum - 07-20-2010, 09:09 AM
Passing data to view - by El Forum - 07-20-2010, 09:13 AM
Passing data to view - by El Forum - 07-20-2010, 09:13 AM
Passing data to view - by El Forum - 07-20-2010, 09:15 AM
Passing data to view - by El Forum - 07-20-2010, 09:16 AM
Passing data to view - by El Forum - 07-20-2010, 09:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB