Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
An Object-Oriented way to build find queries.
PHP
tag: 0.1.3.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
libs
models/behaviors
tests
README.md

README.md

QueryBuilder Behavior

This behavior provides a step-by-step interface to build find options.

Requirements

  • CakePHP 1.3
  • PHP 5.1 or later

Installation

cd app/plugins
git clone git://github.com/tkyk/cakephp-query-builder.git query_builder

Usage

QueryBuilderBehavior provides finder method to build and invoke a find operation.

// method-chain style
$results = $Model->finder('all')
  ->fields('id', 'title')
  ->Model_title('like', '%abc')
  ->order('id ASC', 'created ASC')
  ->limit(10)
  ->invoke();

// property style
$f = $Model->finder('all');
$f->fields = array('id', 'title');
$f->conditions = array('Model.title like' => '%abc');
$f->order = array('id ASC', 'created ASC');
$f->limit = 10;
$results = $f->invoke();

The similar methods paginator and subquery are for pagination and subqueries, respectively.

// pagination
$results = $Model->paginator($Controller)
  ->fields('id', 'title')
  ->Model_title('like', '%abc')
  ->order('id ASC', 'created ASC')
  ->invoke();

 // subquery
 $subqueryStr = $Model->subquery('users', 'User2')
   ->fields('User2.id')
   ->User2_deleted(null)
   ->__toString();
Something went wrong with that request. Please try again.