Download the PHP package windwalker/record without Composer
On this page you can find all versions of the php package windwalker/record. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download windwalker/record
More information about windwalker/record
Files in windwalker/record
Package record
Short Description Windwalker Record package
License LGPL-2.0-or-later
Homepage https://github.com/ventoviro/windwalker-record
Informations about the package record
Windwalker Record
Windwalker Record is a simple ActiveRecord to operate database row.
Installation via Composer
Add this to the require block in your composer.json.
Use Record
New a instance.
Or create a class:
Load A Record
Check row exists
Bind Data
If we have a table with only 3 columns:
| Name |
|---|
| name |
| username |
| password |
The fields which not in this table will be remove after binding data.
That makes our fields in Record will always same as DB table.
Store
Create A New Row
If primary not exists, Record will create a new row in table.
Update A Existing Row
If primary key exists, Record will update it.
Validate
Check method help you validate data.
Then we call validate() before store().
Delete
Mutator and Accessor
Mutator and accessor is a setter and getter to do some extra modification when you access value via magic methods.
This is an example of mutator:
Use camel-case style to define a method, then when you access the created_date field, this method will
be auto executed.
And an example of accessor:
And now you can get DateTime object back:
Casts
Add casts to auto convert value type after read from DB:
Supports casts:
- int | integer
- real | float | double
- string
- bool | boolean
- object
- array | json
- date | datetime
- timestamp
- (Class name)
- (Callback array)
NestedRecord
NestedRecord is a tool help us handle Nested Set Model.
Create Table
Name: categories
| Name | Type | Description | Need For NestedRecord |
|---|---|---|---|
| id | int | Primary Key | |
| parent_id | int | ID of Parent Node | V |
| title | varchar | Category title | |
| path | varchar | Node path | V |
| lft | int | Left key | V |
| rgt | int | Right key | V |
| level | int | Node level | V |
Initialise
Every nested set should have a root node.
NOTE: The root node id is 1.
Create Node
Set as first child of ROOT
Now we will have a new node and it id is 2. Create a new node as last child of 2.
Available positions:
- LOCATION_FIRST_CHILD
- LOCATION_LAST_CHILD
- LOCATION_BEFORE
- LOCATION_AFTER
Move Node
Re Ordering
Move To Other Node
Move to node 3 as last child.
Rebuild
If a tree was not correct, using rebuild to reset all lft, rgt of this branch.
getPath
Method to get an array of nodes from a given node to its root.
getTree
Method to get a node and all its child nodes.
Event
Record has an event system that we can process logic before & after every DB operation.
Add event methods in your Record class.
Or add listeners to Dispatcher (You must install windwalker/event first).
Available events:
- onBeforeLoad
- onAfterLoad
- onBeforeStore
- onAfterStore
- onBeforeDelete
- onAfterDelete
- onBeforeBind
- onAfterBind
- onBeforeCreate
- onAfterCreate
- onBeforeUpdate
- onAfterUpdate