Initial commit
This commit is contained in:
41
app/Controllers/UserController.php
Normal file
41
app/Controllers/UserController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user