Codeigniter 4 – Form Validation with Example

Codeigniter 4 - Form Validation with Example Validation Rules - Required: required - Valid Email: valid_email - Min Length: min_length[5] - Max Length: max_length[10] - Exact Length: exact_length[5] - Alpha: alpha - Alpha Numeric: alpha_numeric - Numeric: numeric - Integer: integer - Decimal: decimal - Greater Than: greater_than[5] - Less Than: less_than[10] - In List:...

Codeigniter 4 – Creating Form for Validation with Example

Codeigniter 4 - Creating Form for Validation with Example Creating a Form - Create a new file in the app/Views directory. - Use HTML to create the form. Example: <form action="<?= site_url('form/submit') ?>" method="post"> <label for="name">Name:</label> <input type="text" name="name" id="name"><br><br> <label for="email">Email:</label> <input type="email" name="email" id="email"><br><br> <input type="submit" value="Submit"> </form> Creating a Validation Class -...

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...

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