Download the PHP package grayphp/micro without Composer
On this page you can find all versions of the php package grayphp/micro. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download grayphp/micro
More information about grayphp/micro
Files in grayphp/micro
Informations about the package micro
PHP Micro Framework
Think big, code small with Micro - the PHP micro framework for web applications.
Installation
Install via composer
Usage/Examples
Abailable Routes:
Route
Middleware
Dynamic Route
controller
Make controller
Middleware
Make Middleware
Database
Your can access to Database using DB() helper.
Basic CRUD:
You can interact directly with the tables to insert/update/delete/select data:
Use ArrayAccess
interface to access to the data using the id
:
DB instance
Select by other fields
If you want to select a row by other key than id
, just use the method get
:
Select or create
Sometimes, you want to get a row or create it if it does not exist. You can do it easily with getOrCreate
method:
Rows
A Row
object represents a database row and is used to read and modify its data:
Queries
A Query
object represents a database query. SimpleCrud uses magic methods to create queries. For example $db->post->select()
returns a new instance of a Select
query in the tabe post
. Other examples: $db->comment->update()
, $db->category->delete()
, etc... Each query has modifiers like orderBy()
, limit()
:
The method get()
executes the query and returns the processed result of the query. For example, with insert()
returns the id of the new row:
select()->get()
returns an instance of RowCollection
with the result:
If you only need the first row, use the modifier one()
:
select()
has some interesting modifiers like relatedWith()
to add automatically the WHERE
clauses needed to select data related with other row or rowCollection:
Query API:
Queries use Atlas.Query library to build the final queries, so you can see the documentation for all available options.
Select / SelectAggregate
Function | Description |
---|---|
one |
Select 1 result. |
relatedWith(Row / RowCollection / Table $relation) |
To select rows related with other rows or tables (relation added in WHERE ). |
joinRelation(Table $table) |
To add a related table as LEFT JOIN . |
getPageInfo() |
Returns the info of the pagination. |
from |
Atlas.Query Select() |
columns |
Atlas.Query Select() |
join |
Atlas.Query Select() |
catJoin |
Atlas.Query Select() |
groupBy |
Atlas.Query Select() |
having |
Atlas.Query Select() |
orHaving |
Atlas.Query Select() |
orderBy |
Atlas.Query Select() |
catHaving |
Atlas.Query Select() |
where |
Atlas.Query Select() |
whereSprintf |
Atlas.Query Select() |
catWhere |
Atlas.Query Select() |
orWhere |
Atlas.Query Select() |
orWhereSprintf |
Atlas.Query Select() |
whereEquals |
Atlas.Query Select() |
limit |
Atlas.Query Select() |
offset |
Atlas.Query Select() |
distinct |
Atlas.Query Select() |
forUpdate |
Atlas.Query Select() |
setFlag |
Atlas.Query Select() |
bindValue |
Atlas.Query Select() |
Update
Function | Description |
---|---|
relatedWith(Row / RowCollection / Table $relation) |
To update rows related with other rows or tables (relation added in WHERE ). |
set |
Atlas.Query Update() |
setFlag |
Atlas.Query Update() |
where |
Atlas.Query Update() |
orWhere |
Atlas.Query Update() |
catWhere |
Atlas.Query Update() |
orderBy |
Atlas.Query Update() |
limit |
Atlas.Query Update() |
offset |
Atlas.Query Update() |
Insert
Function | Description |
---|---|
orIgnore() |
To ignore silently the insertion on duplicated keys, instead throw an exception. |
set |
Atlas.Query Insert() |
setFlag |
Atlas.Query Insert() |
Delete
Function | Description |
---|---|
relatedWith(Row / RowCollection / Table $relation) |
To delete rows related with other rows or tables (relation added in WHERE ). |
setFlag |
Atlas.Query Delete() |
where |
Atlas.Query Delete() |
orWhere |
Atlas.Query Delete() |
catWhere |
Atlas.Query Delete() |
orderBy |
Atlas.Query Delete() |
limit |
Atlas.Query Delete() |
offset |
Atlas.Query Delete() |
Lazy loads
Both Row
and RowCollection
can load automatically other related rows. Just use a property named as related table. For example:
This allows make things like this:
Use magic methods to get a Select
query returning related rows:
Solving the n+1 problem
The n+1 problem can be solved in the following way:
You can perform the select by yourself to include modifiers:
For many-to-many relations, you need to do one more step:
Relate and unrelate data
To save related rows in the database, you need to do this:
Pagination
The select
query has a special modifier to paginate the results:
All versions of micro with dependencies
ext-mbstring Version *
ext-openssl Version *
vlucas/phpdotenv Version ^5.5
phpmailer/phpmailer Version ^6.6
nesbot/carbon Version ^2.62.1
psr/simple-cache Version ^1.0|^2.0|^3.0