<?php
/**
* Class User
* Application/controller/user.php
*/
class User extends Controller
{
function my__construct($user_model)
{
include 'application/model/usermodel.php';
}
spl_autoload_register('my__construct');
public function index()
{
// load views/partials.
require 'application/views/partials/header.php';
require 'application/views/partials/footer.php';
// run the login() method in the login-model, put the result in $login_successful (true or false)
// perform the login method, put result (true or false) into $login_successful
$login_successful = $user_model->login();
// check login status
if ($login_successful) {
// if YES, then move user to dashboard/index (btw this is a browser-redirection, not a rendered view!)
header('location: ' . URL . 'user/profile');
} else {
// if NO, then move user to login/index (login form) again
header('location: ' . URL . 'user/access');
}
}
public function access() {
// @TODO fix $this->view->render
require 'application/views/partials/header.php';
require 'application/views/user/access.php';
require 'application/views/partials/footer.php';
}
public function create() {
$user_model = $this->loadModel('UserModel');
//check if we have POST data to create a new user
if (isset($_POST["submit_add_user"])) {
//@TODO Add password encryption, prefered BCrypt.
$user_model->create($_POST["fornavn"], $_POST["efternavn"], $_POST["sted"], $_POST["password"], $_POST["email"]);
}
// where to go after user has been added
header('location: ' . URL . 'user/access');
}
public function delete() {
// if we have an id of a user that should be deleted
if (isset($user_id)) {
$user_model->deleteUser($user_id);
}
// where to go after user has been deleted
header('location: ' . URL . 'user/access');
}
public function profile() {
// Fetch user details for form to edit
$user_details = $user_model->user();
}
}
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).