Download the PHP package chinpei215/cakephp-stackable-finder without Composer
On this page you can find all versions of the php package chinpei215/cakephp-stackable-finder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chinpei215/cakephp-stackable-finder
More information about chinpei215/cakephp-stackable-finder
Files in chinpei215/cakephp-stackable-finder
Package cakephp-stackable-finder
Short Description CakePHP 2.x plugin to make it possible to stack custom finders
License MIT
Homepage https://github.com/chinpei215/cakephp-stackable-finder
Informations about the package cakephp-stackable-finder
StackableFinder Plugin for CakePHP 2.x
Requirements
- CakePHP 2.x
- PHP 5.3+
Installation
- Put
StackableFinder
directory into your plugin directory. You can also install via Composer. - Enable
StackableFinder
plugin in yourapp/Config/bootstrap.php
file. - Enable
StackableFinder.StackableFinder
behavior in your model.
Usage
You can start stacking finders by calling q()
, and you can execute the query and get the resutls by calling exec()
.
Note that q()
method returns an instance of StackableFinder
. The object also has find()
method like a Model - so you can use fluent interface, but it is not a sub-class of Model.
So you cannot call any other methods implemented by Model.
Instead, you can use where()
or some other 3.x compatible methods for building queries.
Subqueries
You can make subqueries like the following:
You will see that IN ?
appears after the field name in the left-hand side, and you will see also that $q
appears inside an []
in the right-hand side.
It is not compatible with 3.x but it is nessecary at this time in 2.x.
Getting results
As mentioned above, you can do it by calling exec()
but there are some other ways to get the results of the query.
You can iterate the StackableFinder
object directly.
Or you can use first()
or count()
instead of exec()
.
This is same as the following:
But, note that stacking find('first')
or first()
after find('list')
doesn't work.
Because _findFirst()
doen't returns the first result actually. That returns the element with index 0
.
So this is a bad example:
You will get an empty array instead of the first item of the list.
Also note that stacking find('count')
or count()
after find('list')
doesn't work.
Because _findCount()
expects an array like [['Model' => ['count' => N ]]]
, but _findList
changes the array before it get called.
You can override these methods in your model to change the behaviors, if necessary.