Passing $_POST from view to model in MVC I am building my own MVC structured project to learn the concepts of MVC and I need to pass $_POST variables from my view (which is a login form) to the model. Down below is my approach but I wonder if it is the correct way to do it or there is a better one for example passing it into the construct or maybe putting $_POST inside an array.. What do you think?

The login method is to generate a token for my login form in the view which is for the cookie 



class Users
{    

    protected $db;

    public function __construct() 
    {
        $this-&gt;db = Database::instance();
    }

    public function login()
    {
        return self::genToken();        
    }

    public function loginAction()
    {
        $username   = $_POST['username'];
        $password   = $_POST['password'];
        $rememberMe = $_POST['remember_me'];
        $token      = $_POST['token'];
        $redirect   = null;
        ...

    }
    public function genToken()
    {
       return md5(uniqid());
    } 


Here is my view. (http://localhost/MVC/public/user/login)

&lt;form id="login" method="post" action="http://localhost/MVC/public/user/loginAction" class="well"&gt;
    &lt;div class="form-group"&gt;
        &lt;label&gt;Username&lt;/label&gt;
        &lt;input type="text" name="username" class="form-control" placeholder=""&gt;
    &lt;/div&gt;
    &lt;div class="form-group"&gt;
        &lt;label&gt;Password&lt;/label&gt;
        &lt;input type="password" name="password" class="form-control" placeholder="Password"&gt;
        &lt;input type="hidden" name="token" value="&lt;?= $data['token'] ?&gt;" /&gt;
        &lt;div class="help-block text-right"&gt;&lt;a href="#"&gt;Forget the password?&lt;/a&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="checkbox"&gt;
        &lt;label&gt;&lt;input type="checkbox" name="remember_me" value="1" checked /&gt; Remember Me&lt;/label&gt;
    &lt;/div&gt;
    &lt;button type="submit" class="btn btn-default btn-block" name="signin"&gt;Login&lt;/button&gt;
&lt;/form&gt;
Superglobals

I cloned your repo and it looks like you've already taken my advice about passing in the superglobals instead of using them directly from your methods.

Formatting

I would have also commented on the formatting but you've also significantly improved that since posting the question. Cheers!

Commenting

The next good habit to get into is commenting, which s just as important as formatting and entirely lacking in this project. You should always put a short comment above every method explaining what it does, what parameters it takes and what it returns so you (and people maintaining the code in 
 the future) don't have to read the code to figure out what it does.

I see you're using NetBeans. I Like NB too. NB makes documenting your PHP and JS classes and functions very easy. I looked and I could not find any good documentation because I cannot remember what it's called, so I'll just explain the features as best I can.

Auto-commenting Pro Tip

Netbeans will actually do most of the work for you - place the cursor on the empty line just above the start of the function and type /** and hit the enter key. Netbeans will create the rest of the comment including the parameters and the return type (if there is one).

This is what Netbeans generated for your loginAction method.

/**
 * 
 * @param type $username
 * @param type $password
 * @param type $rememberMe
 * @param type $token
 * @param type $redirect
 */
public function loginAction($username, $password, $rememberMe, $token, $redirect = null)


Now you just need to write a short description on the first blankk line and fill in the types (if NB wasn't able to guess them already). eg..

/**
 * Authenticate a user and start a session
 * @param String $username - The username of the user
 * @param String $password - The user's password
 * @param Boolean $rememberMe - Set a cookie?
 * @param String $token - Login token
 * @param String|Null $redirect - URL to redirect to
 */
public function loginAction($username, $password, $rememberMe, $token, $redirect = null)


Now, not only will this be easy to read and maintain, but NetBeans will actually parse these comments and show you what parameters are required when you start to type the method name: