Eager and Lazy Loading in CodeIgniter 4

Efficiently managing database queries is crucial for application performance. To simplify it, I made a nice CodeIgniter 4 library that provides two techniques for loading related data: eager loading and lazy loading. composer require michalsn/codeigniter-nested-model These approaches allow developers to fetch related models in an efficient and intuitive way. Here’s a comprehensive guide to understanding and using these techniques. Eager Loading Eager loading fetches related data in advance, minimizing the number of database queries. To implement eager loading, you must define the relations between your models. ...

December 12, 2024 · 3 min

Alerts for htmx and CodeIgniter 4

In a traditional CodeIgniter 4 application, setting up alerts is quite simple. We can simply write a few lines of code or use a dedicated library like codeigniter4-alerts. Things get complicated, however, when we use htmx and want the alerts to interact with the way it works. Here a library dedicated to work with htmx can come to the rescue. Installation Installation via composer is very simple: composer require michalsn/codeigniter-htmx-alerts Next, we can add a container in which alerts will be displayed in our view (or main layout). ...

September 26, 2024 · 1 min

CodeIgniter Markdown Pages

Markdown Pages project allows you to map Markdown files to collections and easily list or read data from them. In addition to the Markdown parser, we also have the ability to parse YAML sections, where you can put a lot of useful information. How to start: composer michalsn/codeigniter-markdown-pages Basic usage: $markdownPages = service('markdownpages', ROOTPATH . 'pages'); // Get the first directory $dir = $markdownPages->dirs()->first(); echo $dir->getName() // prints: Quick Start echo $dir->getSlug() // prints: quick-start foreach($dir->getFiles()->items() as $file) { echo $file->getName(); // prints: Installation echo $file->getSlug(); // prints: installation echo $file->getPath(); // prints: quick-start/installation echo $content->parse()->getContent(); // prints: parsed markdown from file echo $content->parse()->getMeta(); // prints: parsed YAML as key -> value } This project use Collection class pretty much everywhere so please get familiar with it to use this package comfortably. ...

December 29, 2023 · 1 min

CodeIgniter Queue

While CodeIgniter 4 itself doesn’t have a built-in queue system, I have built one which rely on the database handler. But what is a queue? It’s a system that allows you to schedule and manage background tasks or jobs to be executed in the given order. These jobs can include sending emails, processing data, generating reports, and more. Using a queue system helps offload time-consuming or resource-intensive tasks from the main application, ensuring that the application remains responsive. ...

October 14, 2023 · 2 min

CodeIgniter Tags

Tags provide a way to organize content and improve the user’s experience by helping them discover related articles and navigate through a website’s content more efficiently. They are particularly useful in content-heavy websites or blogs where there’s a wide range of topics and subjects covered. This blog also uses tags system. These tags help categorize and organize content to make it more accessible and searchable. Since there was no tags library for CodeIgniter 4, I decided to write one. The codeigniter-tags is designed to work with many content types at once, so we can use it in many models. ...

September 28, 2023 · 2 min