Declare and show variables in Model MVC

Asked

Viewed 100 times

0

I am using the MVC standard, and I need to declare the value of a variable inside the model file and I ended up doing this:

public $user_id = null;
public $user_name = "";
public $user_email = "";
public $user_is_logged_in = false;

public function doLoginWithPostData($user_name, $user_password) {
    ...
    $this->user_id = $result_row->id;
    $this->user_name = $result_row->username;
    $this->user_email = $result_row->mail;
    $this->user_is_logged_in = true;
    ...
}

However, when I’m trying to show these variables in a controller, it simply appears with no value. Var_dump:

object(Model)#4 (5) { ["user_id"]=> NULL ["user_name"]=> string(0) "" ["user_email"]=> string(0) "" ["user_is_logged_in"]=> bool(false) ["db"]=> object(PDO)#3 (0) { } }

EDIT: I realized that information is only lost when I switch pages

  • If you want to log in, you must save the data to a session or cookie so that you can access it when you switch pages. The behavior there is as expected, stores and accesses while this class is in memory. Reloaded, lost.

  • So leave it at that? http://pastebin.com/wZKw1VJH

  • Yes, of course it’s a "loose" example, but that’s the concept,

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.