Welcome Guest, Not a member yet? Register   Sign In
Passing Data from Constructor to Method
#1

[eluser]Unknown[/eluser]
I'm new to CodeIgniter and I'm creating a login-protected site that follows this logic to verify a login:

__constructor()

- Check if the user's ID is stored in the session.
- If so, make sure they are a valid user (need this data anyway on the page).
- If neither check passes, redirect to login.

In an effort to reduce the number of queries performed, I wanted to find a way to start building my $data array early. Just doing this doesn't seem to work:

Code:
function __constructor() {
    $data = array('Foo');
}

function method() {
    array_push($data, 'Bar');
}
No problem, doing this seems to:

Code:
function __constructor() {
    // Get user data.
    $this->data = array('Foo');
}

function method() {
    array_push($this->data, 'Bar');
    $this->data['test'] = TRUE;
    // Pass user data and the above to a view.
    $this->load->view('page-template', $this->data);
}
My question is what danger, if any, is there in doing this?


Messages In This Thread
Passing Data from Constructor to Method - by El Forum - 12-07-2009, 12:57 PM
Passing Data from Constructor to Method - by El Forum - 12-08-2009, 12:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB