Codeigniter 4 Tutorial
You find here Codeigniter 4 tutorial videos or source code. Where you can learn Codeigniter 4 framework in easy way and get every Question's answer here.
Translate
Friday, 7 July 2023
Thursday, 1 October 2020
How to link Css and Js Files in Codeigniter 4
3) Add all html files in View folder rename that file .html to .php file and load view in controller like below shown.
<?php namespace App\Controllers;
use CodeIgniter\Controller;
class User extends BaseController
{
public function index()
{
return view('home');
}
public function about()
{
return view('about');
}
}
Saturday, 19 September 2020
Codeigniter 4 Insert Data in Database
1) Without Model (using Query Builder) insert data in database in codeigniter 4
Controller - User.php
location - App/Controller/User.php
<?php namespace App\Controllers;
use App\Models\UserModel;
use CodeIgniter\Controller;
class User extends BaseController
{
public function index()
{
return view('home');
}
public function insert()
{
$data = [ 'name' =>$this->request->getVar('name'),
'email' =>$this->request->getVar('email'),
'password' =>$this->request->getVar('password') ];
$db = \Config\Database::connect();
$builder = $db->table('fullname');
$builder->insert($data);
}
}
?>
View - home.php
Location - app/Views/home.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Insert Data</h1>
<form action="<?php echo site_url('User/insert');?>" method="post">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" placeholder="Enter Name" name="name">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
</html>
2) Codeigniter 4 Insert Data in Database Using Model
- View File Home.php is same you have to change in controller and add UserModel.php file.
Model - UserModel.php
Location - app/Models/UserModel.php
<?php namespace App\Models;
use CodeIgniter\Model;
class UserModel extends Model
{
protected $table = 'fullname'; //table name
protected $allowedFields= ['name','surname','email','password']; //column name of table
}
?>
Controller - User.php
location - app/Controller/User.php
<?php namespace App\Controllers;
use App\Models\UserModel;
use CodeIgniter\Controller;
class User extends BaseController
{
public function index()
{
return view('home');
}
public function insert()
{
$data = [ 'name' =>$this->request->getVar('name'),
'email' =>$this->request->getVar('email'),
'password' =>$this->request->getVar('password') ];
$model = new UserModel();
$model->insert($data);
}
}
?>
This You Tube Video has full explaination with Practical, you can watch that video.
Friday, 17 July 2020
How to create library in Codeigniter
Library of Codeigniter Tutorial
this->load->library('email'); $this->email->from('your@example.com', 'Your Name'); $this->email->to('someone@example.com'); $this->email->cc('another@another-example.com'); $this->email->bcc('them@their-example.com'); $this->email->subject('Email Test'); $this->email->message('Testing the email class.'); $this->email->send();
If you are still confuse. This below video will helpbyou and show you detail of library of Codeigniter.
How to download and install Codeigniter in hindi
That is easiest and simplest way to install Codeigniter