Download the PHP package rafaelwendel/ci4tablemaker without Composer
On this page you can find all versions of the php package rafaelwendel/ci4tablemaker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rafaelwendel/ci4tablemaker
More information about rafaelwendel/ci4tablemaker
Files in rafaelwendel/ci4tablemaker
Package ci4tablemaker
Short Description A helper library for the CodeIgniter 4 framework designed to extend the capabilities of the native (View) Table class.
License MIT
Homepage https://github.com/rafaelwendel/CI4TableMaker
Informations about the package ci4tablemaker
CI4TableMaker
CI4TableMaker is a helper library for the CodeIgniter 4 framework designed to extend the capabilities of the native CodeIgniter\View\Table class.
It simplifies the task of dynamically injecting action columns (such as "Edit", "Delete", or custom buttons) into HTML tables. It features support for conditional action links per row (e.g., showing a button only if the user is an Admin) and dynamic placeholder substitution for database columns in URLs.
🚀 Installation
Add the package to your CodeIgniter 4 project using Composer:
[!NOTE] If you are using the class directly in your project's
app/Libraries/folder without Composer, you can import it using the local namespaceuse App\Libraries\TableMaker;. If you installed the package via Composer, import it using the package namespace:use CI4TableMaker\TableMaker;.
🛠️ How to Use
1. Basic Usage
In your Controller, fetch your users' dataset (with columns id, name, and profile), define the action links, and send the helper instance to your View.
In your View (app/Views/users/index.php), simply print the object:
| The code produces the following result: | ID | Name | Profile | Actions |
|---|---|---|---|---|
| 1 | Roger Federer | Admin | Delete | |
| 2 | Rafael Nadal | Author | Delete | |
| 3 | Novak Djokovic | Editor | Delete | |
| 4 | Andy Murray | Admin | Delete |
2. Conditional Action Links
You can set conditions so an action link is only displayed if specific criteria are met. The library supports the following operators: ==, ===, !=, >, <, >=, <=.
For example, to display an "Advanced Settings" link only for users whose profile is 'Admin':
| Result: | ID | Name | Profile | Actions |
|---|---|---|---|---|
| 1 | Roger Federer | Admin | Advanced Settings | |
| 2 | Rafael Nadal | Author | Delete | |
| 3 | Novak Djokovic | Editor | Delete | |
| 4 | Andy Murray | Admin | Advanced Settings |
3. Dynamic URL Placeholders
The library replaces wildcards inside your URL paths using any column key available in your dataset.
4. Selecting and Ordering Columns
Using the setColumns() method, you can specify exactly which columns of your dataset should be displayed in the final HTML table and define their exact order.
📖 Methods Reference
setHeading(...$heading): void
Sets the table headers. Accepts an array or discrete arguments.
setFooting(...$footing): void
Sets the table footer. Accepts an array or discrete arguments.
setTemplate(array $template): void
Sets the HTML table template using CodeIgniter 4's Table library array layout.
setData(iterable $data): void
Injects the dataset (array of arrays, array of objects, or database query results) that will populate the table.
setUrlBase(string $urlBase): void
Sets the prefix URL base for all action link paths.
setColumns(array $columns): void
Specifies which columns should be displayed in the HTML table and sets their render order.
setSeparator(string $separator): void
Defines the separator string inserted between action links. Default: .
addLink(string $path, ?string $param, string $title, array|string $attr = '', ?array $condition = null): void
Adds an action link.
$path: The link path (e.g.,'edit/{id}').$param: Maintained for legacy compatibility. Key whose value replaces{param}in the URL.$title: The link label or button HTML.$attr: Extra link attributes likeclass,id, ortarget(accepts string or array).$condition: Conditional array configuration (['field' => ..., 'operator' => ..., 'value' => ...]).
display(bool $returnData = false, string $indexTitle = 'actions'): array|string
Generates and returns the table as an HTML string by default, or returns the processed dataset as an array if $returnData is true.
📄 License
This project is licensed under the MIT License.