1️⃣ Introduction to CodeIgniter 🛠️
- 🔍 What is CodeIgniter?
- 🕰️ History & Versions of CodeIgniter (CodeIgniter 3 vs. CodeIgniter 4)
- ⚖️ CodeIgniter vs Other PHP Frameworks (Laravel, Symfony, Yii)
- 🏗️ MVC Architecture in CodeIgniter
2️⃣ Installing CodeIgniter 💻
✅ System Requirements
- PHP 7.4+
- Composer installed
🔽 Downloading CodeIgniter from Official Website
📥 Installing via Composer
composer create-project codeigniter4/appstarter my_project
📂 Directory Structure of CodeIgniter 4
🌍 Setting Base URL in .env
app.baseURL = 'http://localhost/my_project/'
🚀 Running the Development Server
php spark serve
3️⃣ CodeIgniter Configuration ⚙️
- 📜 Understanding
app/Config/App.php - 🗄️ Configuring Database in
app/Config/Database.php - 🔧 Environment Configuration (
.env file) - 🛠️ Enabling Debug Mode
- ⏳ Setting Up Timezone in
app/Config/App.php
4️⃣ CodeIgniter Routing 🚦
🛤️ Basic Routing
$routes->get('/home', 'Home::index');
📝 Parameterized Routes
$routes->get('/user/(:num)', 'User::profile/$1');
🔗 Redirect Routes
return redirect()->to('/dashboard');
5️⃣ CodeIgniter Controllers 🎮
📌 Creating a Controller
php spark make:controller UserController
6️⃣ CodeIgniter Models 🗄️
📌 Creating a Model
php spark make:model UserModel
📊 Querying the Database
$users = $this->UserModel->findAll();
7️⃣ CodeIgniter Views & Templating 🖼️
🔄 Passing Data to Views
return view('home', ['name' => 'John']);
🖥️ Using Layouts & Partials
echo view('header');
echo view('content');
echo view('footer');
8️⃣ CodeIgniter Database & Migrations 🗄️
📝 Creating a Database Migration
php spark make:migration CreateUsersTable
⏳ Running Migrations
php spark migrate
🔄 Rolling Back Migrations
php spark migrate:rollback
9️⃣ CodeIgniter CRUD Operations 📝
📥 Insert Data into Database
$this->db->table('users')->insert($data);
📤 Retrieve Data from Database
$query = $this->db->table('users')->get();
🔟 CodeIgniter Form Handling & Validation ✅
✅ CodeIgniter Form Validation
$validation->setRule('email', 'Email', 'required|valid_email');
1️⃣1️⃣ CodeIgniter Session & Cookies 🍪
🔐 Using Sessions
session()->set('user', $userData);
🔍 Retrieving Session Data
$user = session()->get('user');
1️⃣2️⃣ CodeIgniter Authentication & Authorization 🔑
- 👤 User Login & Registration
- 🔒 Hashing Passwords using
password_hash() - 🏆 Role-Based Access Control (RBAC)
1️⃣3️⃣ CodeIgniter File Upload & Handling 📂
📤 Uploading Files
$file = $this->request->getFile('userfile');
$file->move(WRITEPATH.'uploads');
1️⃣4️⃣ CodeIgniter RESTful API Development 🌐
📡 CodeIgniter API Controller
php spark make:controller Api/UserController --restful
📊 JSON Response in API
return $this->response->setJSON($data);
1️⃣5️⃣ CodeIgniter Events & Hooks 🔄
🚀 Defining Custom Events
Events::trigger('user_registered', $user);
1️⃣6️⃣ CodeIgniter Email & Notifications 📩
📧 Sending Emails in CodeIgniter
$email->setTo('user@example.com')
->setSubject('Welcome')
->setMessage('Hello')
->send();
1️⃣7️⃣ CodeIgniter Task Scheduling & Queues 🕒
- 🔄 Running Cron Jobs
- 📤 Using Queues (Beanstalkd, Redis)
1️⃣8️⃣ CodeIgniter Testing 🧪
📝 Writing Unit Tests
php spark make:test UserTest
✅ Running Tests
php spark test
1️⃣9️⃣ CodeIgniter Security Best Practices 🔒
🛡️ CSRF Protection
2️⃣0️⃣ CodeIgniter Deployment & Optimization 🚀
- 🚢 Deploying on Shared Hosting / AWS / DigitalOcean
- ⚡ Enabling Cache in CodeIgniter
- 📊 Database Indexing for Optimization
📌 Sorting Example in CodeIgniter 🔄
📊 Sorting Data in Controller
public function sortUsers()
{
$users = $this->db->table('users')->orderBy('name', 'asc')->get()->getResult();
return view('users_list', ['users' => $users]);
}
🔍 Sorting in View using Query Parameters
Sort by Name (ASC)
Sort by Name (DESC)