Advance CodeIgniter 4 Framework Tutorials #1 step by Step Login & Registration in CodeIgniter 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to online web tutor i am sanjay from this video session guys we're going to start about advanced go to data for tutorials this is our part one inside this video we will discuss about login and registration inside codeigniter 4. to understand about the complete concept of login and registration site codeigniter 4 we need to open this blogging website if i back to browser here we have the blogging website called onlinewavetutorblog.com so what i will do next simply go inside this articles click on codeigniter 4 and i will click on the search bar and let's say that login and registration if i press enter now as we can see that here we have article so simply i will click on this article and inside this whole article we have a clear documentation about login and registration so inside this whole video what we are going to do if i back to slide open a new tab so simply we will start everything from scratch so first of all we will install code igniter 4 next we will create a database after that we need to implement all about the login functionality so we will have login and before login we have registration feature and one more thing when we create any user or let's say that in login functionality if we want user authentication so before that we need a database table so here inside the second step let's say create database and table next we'll have a view file for the registration and login and after login we'll have a profile page and a dashboard page inside profile page we will implement the logout functionality so these are the things we will cover inside this video so back to our documentation now here inside this article this is all about codeigniter version 4.1.1 and by the by the following this first step we're going to download code data for setup so what i will do i will copy this command back to terminal we are currently inside html code igniter iphone 4 blog hyphen articles so simply inside this blog hyphen articles we will create a folder something called code igniter iphone 4 so what i will do i will change the name something let's say app hyphen login so simple press enter now it is going to install or create a codec data for application inside our local machine now as we can see that we have installed so if i back to folder structure and here's we can see that we have a directory structure what i will do next simply i will open this folder inside this vs code editor so here is the project inside vs code back to our article we have successfully installed our setup now next we into settings environment variables simply this block means that we need to make this env file to dot env file because right now this env file is not in use if we want to use this env then we need to convert into dot env file it means simply we need to add dot in front of this word as we can see that inside this env file we have several keywords means these are environment variables so we will be able to use these variables if and only if we will make it as dot env if i back to our article so simply either we can rename or we have a simple command that is cp env to dot env and currently we need to go inside app login folder because here at this stage we are currently inside this blog articles now inside this app hyphen login which is our project i will copy this command called cpenv to dot env so if i press enter now go inside this editor reload this and as we can see that we have created a copy of this env to dot env now successfully we can access all the environment variables from this file back to article the second stage we had done now next we need to convert our environment from production to development why we are converting because in case let's say that we are working while working if suppose we have some programming mistakes so by converting from production to development in the development mode we will be able to see all the errors inside our screen back to editor go inside this dot env remove this hash symbol from here and simply convert from production to development back to documentation now next we need to create a database and table inside our application so here's we can see that we have a database this is the mysql command to create a database so what i will do i will change the name of database something let's say codeigniter 4 instead of that i will make it as app hyphen login means underscore login so simply copy this command back to phpmyadmin go inside the sql tab and press here the go button now as we can see that we have created app underscore login database now if i reload this structure go inside this database and here we have this database as created back here inside this article now next we need to create a table this is tbl underscore users now inside this table we have the columns as name email phone number and password inside this users table we will register our users from application and store inside this table so i will copy this mysql command go here inside this database we need to create our tpl underscore users table i will copy and paste the command inside the sql tab and press here for this go button now as you can see that inside this database we have a single table called table underscore users and inside this table these are the columns we have back to article we have created our table now next we need to connect our code igniter for setup to database so for that we need to open dot env file inside dot enb file we will see some variables let's say hostname database username so inside that we need to set the database what we have created so back to editor go inside this dot env and here we have default.hostname so simply first we need to remove all these has symbol in front of all these variables host name is localhost and the database we have called app underscore login and in my case the username of phpmyadmin is something admin and the password is something had been added the rate one two three now successfully i have connected the database with our codeigniter for setup go inside this article now next we need to create some application routes all the application routes inside codeigniter4 we will do inside this app config and routes.php file so inside this file what i will do simply i will copy all the routes and these routes include a user controller inside user controller we have a register method login method also we have the second controller called dashboard and inside this dashboard controller we will have a index method now inside the same user controller we will have two more methods called profile and logout and inside each route we have attached the filter called no auth and auth we will understand the concept of filters in a second so first of all copy all the routes from here back to editor go inside this routes.php and after this home page route i have copied and pasted back to article now next we need to create our two filters so before that we need to create a model so what i will do simply copy this spar command back to terminal pasting it here and the command is something php spark make model and here we have the model name called user we have added hyphen hyphen suffix it means that it will create user model dot php file inside models folder so if i press enter file created successfully now as you can see that inside these models we have user model dot php keep in mind here we have passed the name called user but after adding this suffix automatically it adds model with this keyword now if i back to editor reload this directory structure now if you go inside this app models now we will be able to see this user model dot php file now next we need to configure this file it means we need to pass the table name and in our case the table name is something called table underscore users and inside this alert fields we need to pass the fills which is going to take the mass assignment values like name email phone number and password what i mean inside this table these are the columns needs value so we will insert the values inside these four columns from our front end so we need to write all these column names inside this allot files back to article now here is the complete code of user model so i will copy go here remove all the code and paste it here now inside this model file all the things remain same only we have created two methods here we have before insert which i have passed inside this before insert callback it means when we insert any data inside this tbl underscore users table before insert this method will be triggered what this method will do it will call a password hash method and inside this password hash we are passing our data and simply it is picking the password field from input and converting into a hashed value back to article now next we need to create our codeigniter for filters so first of all we need to create auth filter so simply copy this command that terminal pasting it here pressing enter now as you can see that inside our app folder we have a filters folder and inside filters folder we have auth.php now go inside filters and here's you can see that we have ourauth.php file back to article now here we have the complete code of auth.php so simply i will copy go here remove all the code and pasting it here now inside this file what we are doing simply when we have created filter a free of filter class basically contains two methods called before and after now inside this before method what we had done we have checked a session variable called is logged in if inside this variable if we have value then it's okay otherwise we need to redirect user inside login page so this auth filter is going to check all about the session of logged in user if session is active it means we are currently logged in otherwise it will redirect that user to login page back to blog now next we need to create another filter called not so i will copy this command back terminal pasting it here pressing enter it has created another filter called node.php inside this filters folder if i back to article copy the complete code go here if i go inside filters folder here is the file and inside this filter class as you can see that we have a before method as well as after method so i will remove all the code and paste the code what we have copied from ball blog article now inside this no auth class inside this filter we have implemented a condition inside this before method is that also it is checking that if session is active then it will go and redirect user inside dashboard page there is a slight difference between auth know what filter inside odd filter we are checking that if suppose we don't have any value redirect user inside login page but in case of no earth we are checking that if session is active user is logged in then we need to redirect user to dashboard page so these are the filters we have assigned inside each of the route what we have created here black to blog article now next we have successfully created our two filters called auth and no earth next into set inside filters.php file inside config folder back to editor go inside our config folder inside this config folder we will have a file called filters.php when we have created several filters inside application we need to configure inside this file otherwise these files are useless back to filters.php go here inside this blog article simply add these two lines inside header add to header so we are adding now next we to update this aliases variable so i will copy these two lines go inside this aliases array here we have and i am pasting it here now we have saved this filters.php next we need to register a custom rule inside application so for that here we have a spark command after running this spar command it will create a folder called validation inside app directory if i back to editor now before running that command if we see inside this app folder we don't have any validation folder but when we run this command to create custom validation this command automatically will create a validation folder inside app directory so copy that go to terminal and let's run that so php spark make validation user rules if i back to editor go and reload now as you can see that inside this app directory we have a validation folder and we have a validation class file something called user rules go here here is the complete code of user rules so simply i will copy go remove this code and pasting it here now next we need to register this custom validation what we have created inside this config folder validation.php again this file is not in use to use this custom validation rule what we have created we need to register this file inside this application to register this validation go inside this config folder here we have a file called validation.php now inside this file first of all we need to import that's where that validation class what we have created and next we need to add this class inside rule sets array so simply copy go here search for rule sets and pasting it here now we have done with the custom validation back to article now next we to create controller file so as we know that we need two controller file called user and dashboard so i will copy this command to create user controller go here pasting it here pressing enter user controller created successfully now next i will copy the second command this will create dashboard controller now go inside editor go and reload controllers folder now inside this controllers folder we have a dashboard we have user.php by default home.php comes with the installation folder now next here we have the complete code of user.php so i will copy go here remove all the codes pasting it here this is inside user.php now next if i scroll down here we have the complete code of dashboard.php so i will copy go here open up dashboard.php and pasting it here back to blog article so we have done all with the user controller as well as dashboard controller now next we need to create some view files so for the first view file we need to we need apparent layout so we need to create app.php inside this layouts folder and these are the two things means will be inside this views folder so what i will do first first of all we need to create a layouts folder inside this views folder so let's see layouts and inside this layouts folder if i copy the whole code of this app.php go to editor create a file called app.php inside layouts folder and pasting it here now inside this view file what actually we are doing we are creating a parent layout inside this parent layout we have some javascript plugin files as well as a bootstrap css file and also we have created a section inside this body which is responsible to put the dynamic content when we extend this parent layout from its child view files if i back to blog article now next we need to create a register view file so we need to create a file called register.php inside this views folder here is the complete code of register.php simply i will copy and paste it inside here now if you go up inside this file as we can see that we are extending our app.php which is apparent layout this is the layouts folder in which this is the file and here all the code we had written inside this container and these all codes are wrapped inside this body section and this body section is nothing it's a dynamic placeholder right here as we can see that inside this body tag so when we compile our application or when we run then dynamically all these contents will go inside this section now next this is all we have done with the register page now next we need to create the login page so if i copy go here let's create a file called login.php copy the whole code of this login.php go and paste it here now inside this file again we are extending putting the dynamic content for this body section go here if i scroll down this is for the profile page so if i copy the file name go inside this views directory creating this profile dot php copy all the code of this file pasting it here now next we need to create the final view file that is called dashboard.php so i will copy go inside this views folder and let's create a file called dashboard.php if i copy the whole code from here and pasting it here so finally step by step we had seen all about code igniter for login and registration setup now finally we need to execute our application so for that simply we need to start our development server so php spark serve so if i press enter right click on that open link so here is the setup now to get over the login page here's we can see that we have a route called login so simply type login now as you can see that we have a login page so currently we don't have any user inside this users table so first of all we need a registration so for registration we have a route instead of login let's register and here we have our registrar page so inside this let's pass some value i will put the dummy value so password is from 1 to 8 password is from 1 to 8. if i copy this email address click on submit so if i back to table click here now as we can see that we have registered a user successfully inside this table now if i go here let's login that user so this is email address password is from one to eight click on submit and as we can see that currently we are on the dashboard page here we have a lookout button so when we click on this logout button it will go and hit all about user controller and inside this controller we have a logout method so inside this method it will destroy all the sessions what we have created and finally redirect user to the login page also if we go and type call profile this is the profile of the user now go to dashboard it's not as it's something dashboard now when we click on this logout button successfully now we have logged out and come into this login page so this is the guys stay by stay video of complete code igniter for login and registration so for this video session guys thank you for watching and have a great day
Info
Channel: Online Web Tutor
Views: 2,187
Rating: undefined out of 5
Keywords: learn codeigniter 4, step by step codeigniter 4, codeigniter 4 tutorials, codeigniter 4 beginners tutorials, learn codeigniter 4 framework, learn codeigniter 4 step by step, codeigniter4, online web tutor codeigniter 4, codeigniter 4 framework, online web tutor, advance codeigniter 4 tutorials
Id: e62m9AOsfg0
Channel Id: undefined
Length: 26min 33sec (1593 seconds)
Published: Mon Mar 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.