Created
October 16, 2020 13:23
-
-
Save blogcacanid/ab9df7e6141710b7443e235ca9deea1a to your computer and use it in GitHub Desktop.
RegisterController.php Login Dan Register System CodeIgniter 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Controllers; | |
use App\Models\UserModel; | |
class RegisterController extends BaseController | |
{ | |
protected $model; | |
public function __construct() | |
{ | |
$this->model = new UserModel(); | |
$this->helpers = ['form', 'url']; | |
} | |
public function index() | |
{ | |
$data = [ | |
'title' => 'Login Dan Register System CodeIgniter 4' | |
]; | |
return view('auth/register', $data); | |
} | |
public function store() | |
{ | |
$name = $this->request->getPost('name'); | |
$email = $this->request->getPost('email'); | |
$password = $this->request->getPost('password'); | |
$user = [ | |
'name' => $name, | |
'email' => $email, | |
'password' => $password | |
]; | |
$save = $this->model->save($user); | |
if ($save) { | |
session()->setFlashdata('success', 'Register Berhasil!'); | |
return redirect()->to(base_url('login')); | |
} else { | |
session()->setFlashdata('error', $this->model->errors()); | |
return redirect()->back(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment