- {$base_url}
/ - {$base_url}
/user/registration - {$base_url}
/user/login
-
Setup CodeIgniter 4 Folder in your local Server
-
Enable
.envFile -
Change
ENVIRONMENTType production to development -
Update Base URL, Time Zone (Asia/Kolkata), Set Debug Toolbar Status
-
Create a new controller
Users.phpand insert basic code -
Create user
login and registrationroutes and controller method -
Create
user login and registrationviews file in the/ViewsFolderapp\Views\users\user_login.phpapp\Views\users\user_registration.php
-
Create
header, nav, footerfiles in the/ViewsFolderapp\Views\component\header.phpapp\Views\component\nav.phpapp\Views\component\footer.php
-
Integrate Bootstrap 4 in the
header.phpfile -
Include
header, footerin the Controller Methods. -
Integrate
Page Titlein the header and Controller File. -
Create
user_registrationanduser_logintemplates with bootstrap 4 code. -
What user information do you want to get?
first_namelast_namemobileemailusernamepasswordconfirm_password
-
Introduction CodeIgniter 4 - POST and GET Request
-
https://codeigniter4.github.io/userguide/incoming/incomingrequest.html
-
Fetch all form post data
print_r($this->request->getPost()); print_r($this->request->getMethod(true));
-
-
If user data showing in the post method then integrate form validation.
<?= $validation->listErrors() ?>
-
Set Value method in the form input fields
-
If all user data fetch in the user controller then create
usersdatabase table- Create a new database
c4-login-registration-system - Create
usersdatabase table - Open C4 Model: https://codeigniter4.github.io/userguide/models/model.html
CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `first_name` varchar(200) NOT NULL, `last_name` varchar(200) NOT NULL, `mobile` varchar(10) NOT NULL, `email` varchar(250) NOT NULL, `username` varchar(250) NOT NULL, `password` text NOT NULL, `created_at` varchar(50) NOT NULL, `updated_at` varchar(50) NOT NULL, `deleted_at` varchar(50) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `email` (`email`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
- Create a new database
-
Integrate
databasein the project .env file -
Integrate
UserModel.phpin the user controller file -
Set Timezone
Asia/Kolkatain theApp.phpconfig file- and set project base url
-
Set
before_insertandbefore_updatemethods in the user model file -
If user data successful saved in the database then use
flash session message- https://codeigniter4.github.io/userguide/libraries/sessions.html
- and show flash message in the view file
-
Use
redirectfunction -
Create user login system
- Define name for route and use route name in the redirect method
-
Create
User DashboardController and create dashboard view filesession()->get("AUTH.first_name"); session()->get("AUTH.last_name";
-
Create User Logout Method
-
Next Topic:
Protecting Routeswithout login users- First Method: Check User Session is not empty in every controller method.
- Second Method: CodeIgniter 4 Filters
-
Create a new Filter file
app/Filters/AuthFilter.php -
Include
AuthFilter.phpFile intoapp/Config/Filters.phpandapp/Config/Routes.phpFiles