Codeigniter 4 – Services with Examples

Codeigniter 4 - Services with Examples What are Services? - Services are a way to organize and reuse code in CodeIgniter 4. - They provide a simple and intuitive way to perform specific tasks, interact with external services, or provide utility functions. - Services are typically used to encapsulate complex logic or functionality that can...

Codeigniter 4 – Pagination with Example

Codeigniter 4 - Pagination with Example Creating Pagination - Use the pager method provided by CodeIgniter 4. Example: $pagination = $this->pager->makeLinks($page, $perPage, $total); Configuring Pagination - Set the perPage variable to the number of items per page. Example: $perPage = 10; - Set the total variable to the total number of items. Example: $total =...

Codeigniter 4 – Creating Database, Model then setting up the configuration

Codeigniter 4 - Creating Database, Model then setting up the configuration Creating a Database - Create a new database using your preferred method (e.g. phpMyAdmin, MySQL Workbench). - Note the database name, username, and password. Setting up Database Configuration - Open the app/Config/Database.php file. - Update the default group with your database settings. Example: public...

Codeigniter 4 – Creating a Library with Example

Codeigniter 4 - Creating a Library with Example Creating a Library - Create a new file in the app/Libraries directory. - Extend the CodeIgniter\Libraries\BaseLibrary class. Example: namespace App\Libraries; use CodeIgniter\Libraries\BaseLibrary; class MyLibrary extends BaseLibrary { public function doSomething() { // Library code here } } Loading a Library - Use the library() method to load...

Codeigniter 4 – Removing “public” and “index.php” with Example

Codeigniter 4 - Removing "public" and "index.php" with Example Removing "public" from URL - Move the contents of the "public" folder to the root directory. - Update the base_url in app/Config/App.php to remove "public". Example: public $baseURL = '(link unavailable)'; - Update the index.php file to remove the "public" directory. Example: require __DIR__ . '/vendor/autoload.php';...

Codeigniter 4 – Getting records from a Model and sending them to a View with Example

Codeigniter 4 - Getting records from a Model and sending them to a View with Example Getting Records from Model - Use the get() method to retrieve records from the database. Example: namespace App\Models; use CodeIgniter\Model; class User extends Model { protected $table = 'users'; protected $primaryKey = 'id'; public function getUsers() { return $this->get();...

Codeigniter 4 – Updating and Deleting using model with Example

Codeigniter 4 - Updating and Deleting using model with Example Updating Data - Use the update() method to update existing data. Example: namespace App\Models; use CodeIgniter\Model; class User extends Model { protected $table = 'users'; protected $primaryKey = 'id'; public function updateUser($id, $data) { return $this->update($id, $data); } } Updating Data with Conditions - Use...

Codeigniter 4 – Query Buider with Model

Codeigniter 4 - Query Buider with Model Query Builder with Model - Use the db property of the Model to access the Query Builder. Example: namespace App\Models; use CodeIgniter\Model; class User extends Model { protected $table = 'users'; protected $primaryKey = 'id'; public function getUsers() { return $this->db->table($this->table)->get(); } } Selecting Data - Use the...

Codeigniter 4 – Creating Models with Examples

Codeigniter 4 - Creating Models with Examples Creating a Basic Model - Create a new file in the app/Models directory. - Extend the CodeIgniter\Model class. - Define the table name and primary key. Example: namespace App\Models; use CodeIgniter\Model; class User extends Model { protected $table = 'users'; protected $primaryKey = 'id'; } Creating a Model...

Codeigniter 4 – Modeling Data and ORM with Example

Codeigniter 4 - Modeling Data and ORM (Object-Relational Mapping) with Example Modeling Data - In CodeIgniter 4, models are used to interact with the database. - Models can be used to perform CRUD (Create, Read, Update, Delete) operations. Creating a Model - Create a new file in the app/Models directory. - Extend the CodeIgniter\Model class....

Shopping cart0
There are no products in the cart!
Continue shopping
0