Download the PHP package rougin/wildfire without Composer
On this page you can find all versions of the php package rougin/wildfire. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rougin/wildfire
More information about rougin/wildfire
Files in rougin/wildfire
Package wildfire
Short Description Query Builder wrapper for Codeigniter 3.
License MIT
Homepage https://roug.in/wildfire/
Informations about the package wildfire
Wildfire
Wildfire is a simple wrapper for the Query Builder Class based on Codeigniter 3. It is inspired from the Eloquent ORM of Laravel.
Installation
Install Wildfire
via Composer:
Basic Usage
Prerequisites
Create a sample database table to be used (e.g., users
):
Then configure the composer_autoload
option in config.php
:
[!NOTE] The value of
composer_autoload
should be thevendor
directory (e.g.,ciacme/vendor/autoload.php
).
Next is to extend the model (e.g., User
) to the Model
class of Wildfire
:
Using Wildfire
With CI_DB_query_builder
After configuring the application, the Wildfire
class can now be used for returning results from the database as Model
objects:
With CI_DB_result
Aside from using methods of Wildfire
, raw SQL queries can also be converted to its Model
counterpart:
Properties of Model
class
The Model
class provides the following properties that helps writing clean code and the said properties also conforms to the properties based on Eloquent ORM
.
Casting attributes
Updating the $casts
property allows the model to cast native types to the specified attributes:
Without native casts
With native casts
Notice that the value of accepted
was changed from string integer ('0'
) into native boolean (false
). If not specified (e.g. age
field), all values will be returned as string except the id
field (which will be automatically casted as native integer, also if the said column exists) by default.
Hiding attributes
To hide attributes for serialization, the $hidden
property can be used:
Without hidden attributes
With hidden attributes
In this example, the gender
field was not included in the result.
Visible attributes
Opposite of the $hidden
property, the $visible
property specifies the fields to be visible in the result:
Without visible attributes
With visible attributes
From the example, only the gender
field was displayed in the result because it was the only field specified in the $visible
property of the User
model.
Using timestamps
Similar to Eloquent ORM
, Wildfire
enables the usage of timestamps by default:
When enabled, it will use the constants CREATED_AT
and UPDATED_AT
for auto-populating them with current timestamps. To modify the names specified in the specified timestamps, kindly create the specified constants to the model (e.g., User
):
[!NOTE] Auto-populating of timestamps in the specified constants is used in
WritableTrait
.
Customizing attributes
When accessing an attribute through the model, Wildfire
uses the same mechanism as from Eloquent ORM
to return the requested attribute from the $attributes
property. To customize the output of an attribute (e.g., converting an attribute to a date format), add a method inside the Model
with a name format get_[ATTRIBUTE]_attribute
:
After creating a method for the specified attribute, the Model
class will call the said method (e.g., get_created_at_attribute
) if the specified attribute is accessed (e.g., $user->created_at
).
Using Traits
Wildfire
provides traits that are based from the libraries of Codeigniter 3
such as Form Validation
and Pagination Class
. They are used to easily attach the specified functionalities of Codeigniter 3
to a model.
PaginateTrait
The PaginateTrait
is used to easily create pagination links within the model:
The $result[0]
returns the computed offset while $result[1]
returns the generated pagination links:
To configure the pagination library, the $pagee
property must be defined in the Model
:
[!NOTE] Please see the documentation of Pagination Class to get the list of its available configuration.
ValidateTrait
This trait is used to simplify the specifying of validation rules to a model:
When used, the $rules
property of the model must be defined with validation rules that conforms to the Form Validation
specification:
[!NOTE] Kindly check its documentation for the available rules that can be used to the
$rules
property.
To do a form validation, the validate
method must be called from the model:
If executed with a view, the validation errors can be automatically be returned to the view using the form_error
helper:
WritableTrait
The WritableTrait
is a special trait that enables the model to perform CRUD operations:
If added, the model can now perform actions such as create
, delete
, and update
:
[!NOTE] When using this trait, the
CREATED_AT
andUPDATED_AT
constants will be populated if the$timestamps
property of a model is enabled.
WildfireTrait
Similar to WritableTrait
, the WildfireTrait
allows the model to use methods directly from the Wildfire
class:
Adding it to a model enables the methods such as find
and get
methods without specifying the database table:
Migrating to the v0.5.0
release
The new release for v0.5.0
will be having a backward compatibility break (BC break). With this, some functionalities from the earlier versions might not be working after upgrading. This was done to increase the maintainability of the project while also adhering to the functionalities for both Codeigniter 3
and Eloquent ORM
. Please see the UPGRADING page for the said breaking changes.
[!TIP] If still using the
v0.4.0
release, kindly click its documentation below: https://github.com/rougin/credo/blob/v0.4.0/README.md
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
Credits
License
The MIT License (MIT). Please see LICENSE for more information.