PHPackages                             chinpei215/cakephp-stackable-finder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. chinpei215/cakephp-stackable-finder

ActiveCakephp-plugin[Database &amp; ORM](/categories/database)

chinpei215/cakephp-stackable-finder
===================================

CakePHP 2.x plugin to make it possible to stack custom finders

0.2.0(10y ago)1029MITPHP

Since Dec 23Pushed 10y ago2 watchersCompare

[ Source](https://github.com/chinpei215/cakephp-stackable-finder)[ Packagist](https://packagist.org/packages/chinpei215/cakephp-stackable-finder)[ Docs](https://github.com/chinpei215/cakephp-stackable-finder)[ RSS](/packages/chinpei215-cakephp-stackable-finder/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![Build Status](https://camo.githubusercontent.com/21e129e08160c07661e250c46f695a1c3aecd2990b4b37f1e816e8f9bd98c36d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6368696e7065693231352f63616b657068702d737461636b61626c652d66696e6465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/chinpei215/cakephp-stackable-finder)[![Coverage Status](https://camo.githubusercontent.com/2a2e5252a47f701c308d97155b9bf9fe6b95b5cc1f9e878066852222e8dca8ff/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6368696e7065693231352f63616b657068702d737461636b61626c652d66696e6465722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/chinpei215/cakephp-stackable-finder?branch=master)

StackableFinder Plugin for CakePHP 2.x
======================================

[](#stackablefinder-plugin-for-cakephp-2x)

Requirements
------------

[](#requirements)

- CakePHP 2.x
- PHP 5.3+

Installation
------------

[](#installation)

- Put `StackableFinder` directory into your plugin directory. You can also install via Composer.
- Enable `StackableFinder` plugin in your `app/Config/bootstrap.php` file.
- Enable `StackableFinder.StackableFinder` behavior in your model.

Usage
-----

[](#usage)

```
$articles = $this->Article->q()
	->find('all', ['conditions' => ['Article.created >=' => '2015-01-01']])
	->findAllByUserId(1) // Magic finder
	->find('published') // Custom finder
	->find('list')
	->exec();
```

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.

```
$this->Article->q()->read(); // Error
```

Instead, you can use `where()` or some other 3.x compatible methods for building queries.

```
$articles = $this->Article->q()
	->select(['Article.id', 'Article.title'])
	->contain('Author')
	->where(['Article.user_id' => 1])
	->order(['Article.id' => 'DESC'])
	->limit(10)
	->offset(0)
	->exec();
```

### Subqueries

[](#subqueries)

You can make subqueries like the following:

```
$q = $this->User->q()->select('id');

$articles = $this->Article->q()
	->where([
		'user_id IN ?' => [$q]
	])
	->exec();
```

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

[](#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.

```
$q = $this->Article->q()->find('list');
foreach ($q as $id => $title) {
	// ...
}
```

Or you can use `first()` or `count()` instead of `exec()`.

```
$articles = $this->Article->q()
	->find('published')
	->first();
```

This is same as the following:

```
$articles = $this->Article->q()
	->find('published')
	->find('first')
	->exec();
```

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:

```
$articles = $this->Article->q()
	->find('list')
	->first();
```

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.

###  Health Score

26

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

3884d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd43c19fdb93b85cba0d01ae5dd6d50ded0c36345c79f114c89906eb5038d863?d=identicon)[chinpei215](/maintainers/chinpei215)

---

Top Contributors

[![chinpei215](https://avatars.githubusercontent.com/u/7399393?v=4)](https://github.com/chinpei215 "chinpei215 (42 commits)")

---

Tags

cakephpstackcustomfinders

### Embed Badge

![Health badge](/badges/chinpei215-cakephp-stackable-finder/health.svg)

```
[![Health](https://phpackages.com/badges/chinpei215-cakephp-stackable-finder/health.svg)](https://phpackages.com/packages/chinpei215-cakephp-stackable-finder)
```

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.6k10](/packages/helsingborg-stad-municipio)[andreyryabin/sprint.migration

bitrix migration module

206212.7k2](/packages/andreyryabin-sprintmigration)[pressbooks/pressbooks-book

This theme is named after Canadian media theorist Marshall McLuhan, who coined the phrase “the medium is the message.” It is designed for academic writing and is also suitable for fiction. Headings are set in Cormorant Garamond, and body type is set in Lora.

226.7k](/packages/pressbooks-pressbooks-book)[cpierce/cakephp-sybasedb

CakePHP plugin to handle PDO MSSQL Connections using dblib

1033.9k](/packages/cpierce-cakephp-sybasedb)[imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

137.7k3](/packages/imsamurai-cakephp-serializable-behaviour)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
