42 lines
948 B
PHP
42 lines
948 B
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Core\Controller;
|
|
use App\Models\User;
|
|
|
|
|
|
class UserController extends Controller {
|
|
public function index() {
|
|
// 1. Get data from a Model
|
|
$users = User::all();
|
|
|
|
// 2. Pass data to the view via the base render() method
|
|
return $this->render('users/index', [
|
|
'title' => 'All Users',
|
|
'users' => $users
|
|
]);
|
|
}
|
|
public function store() {
|
|
User::create([
|
|
'username' => $_POST['username'],
|
|
'email' => $_POST['email'],
|
|
'password' => password_hash($_POST['password'], PASSWORD_DEFAULT)
|
|
]);
|
|
header('Location: /users');
|
|
}
|
|
|
|
// Update a user
|
|
public function update() {
|
|
User::updateById($_POST['id'], [
|
|
'email' => $_POST['email']
|
|
]);
|
|
}
|
|
|
|
// Delete a user
|
|
public function destroy() {
|
|
User::deleteById($_GET['id']);
|
|
}
|
|
}
|
|
?>
|