Welcome Guest, Not a member yet? Register   Sign In
Undefined variable: data
#1

[eluser]MrCevic[/eluser]
I read http://ellislab.com/forums/viewthread/148359/ and http://ellislab.com/forums/viewthread/106551/ but none of them help me solve the problem I have.

Here's my controller
Code:
class Entry extends Controller {

function __construct() {
    parent::Controller();
    $this->load->model('Entry_model', '', TRUE);
}

function debug() {
    $data['stuff'] = "Debug";
    $data['morestuff'] = "More debug stuff";
    $this->load->view('debug', $data);
}

and this is my debug.php view:

Code:
<p>&lt;?=$stuff?&gt;</p>
<p>&lt;?=$morestuff?&gt;</p>
&lt;?php
echo '<pre>';
var_dump ($data);
echo '</pre>';
?&gt;

And this is my rendered html:

Quote:Debug

More debug stuff

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/debug.php
Line Number: 5

What am I doing wrong?
#2

[eluser]pickupman[/eluser]
The variable $data has not been set. When you are passing the $data array to a view it's array keys become the variables in your view. So in your example, for $data to be a variable in your view you would need to have:
Code:
$data['data'] = 'some string, array, or object'; //or
$data['data'] = $data; //this is kind of weird but would accomplish your dump
$this->load->view('debug',$data);




Theme © iAndrew 2016 - Forum software by © MyBB