Skip to main content

I am building my own MVC frameworkstructured 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

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) Username Password " />
        <div class="help-block text-right"><a href="#">Forget the password?</a></div>
    </div>
    <div class="checkbox">
        <label><input type="checkbox" name="remember_me" value="1" checked /> Remember Me</label>
    </div>
    <button type="submit" class="btn btn-default btn-block" name="signin">Login</button>
</form>

I am building my own MVC framework 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

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) Username Password " />
        <div class="help-block text-right"><a href="#">Forget the password?</a></div>
    </div>
    <div class="checkbox">
        <label><input type="checkbox" name="remember_me" value="1" checked /> Remember Me</label>
    </div>
    <button type="submit" class="btn btn-default btn-block" name="signin">Login</button>
</form>

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

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) Username Password " />
        <div class="help-block text-right"><a href="#">Forget the password?</a></div>
    </div>
    <div class="checkbox">
        <label><input type="checkbox" name="remember_me" value="1" checked /> Remember Me</label>
    </div>
    <button type="submit" class="btn btn-default btn-block" name="signin">Login</button>
</form>
Source Link

Passing $_POST from view to model in MVC

I am building my own MVC framework 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

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) Username Password " />
        <div class="help-block text-right"><a href="#">Forget the password?</a></div>
    </div>
    <div class="checkbox">
        <label><input type="checkbox" name="remember_me" value="1" checked /> Remember Me</label>
    </div>
    <button type="submit" class="btn btn-default btn-block" name="signin">Login</button>
</form>