2017 © Pedro Peláez
 

cakephp-plugin query-builder

CakePHP behavior to perform queries by Object-Oriented way

image

tkyk/query-builder

CakePHP behavior to perform queries by Object-Oriented way

  • Friday, December 28, 2012
  • by tkyk
  • Repository
  • 1 Watchers
  • 17 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

QueryBuilder Behavior

An Object-Oriented way to build find queries., (*1)

Requirements

  • CakePHP 2.0
  • PHP 5.3 or later

Installation

cd app/Plugin
git clone git://github.com/tkyk/cakephp-query-builder.git QueryBuilder

I recommend you to checkout a versioning tag rather than a development branch., (*2)

cd app/Plugin/QueryBuilder
git checkout x.y.z.w

The finder method

This behavior provides finder method, which encapsulates a find call and its options., (*3)

$findAll = $Model->finder('all');
$findFirst = $Model->finder('first');
$findCustom = $Model->finder('custom_find');

You can set and update the options by assigning its properties., (*4)

$findAll->fields = array('id', 'title');
$findAll->conditions = array('Model.title like' => '%abc');
$findAll->order = array('id ASC', 'created ASC');
$findAll->limit = 10;

Then you can invoke the find operation., (*5)

$results = $findAll->invoke();

And Set::* methods can be applied to the find results., (*6)

// This is equivalent to Set::extract($Model->find('all', ...), '/Model/title')
$titles = $findAll->invoke('extract', '/Model/title');

In addition to the property style assignments described above, method chain style is also supported to set and update the options., (*7)

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

Pagination and Subquery

The similar methods paginator and subquery are provided for pagination and subqueries, respectively., (*8)

// pagination
$results = $Model->paginator($Controller->Paginator)
  ->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();

The Versions

28/12 2012

dev-master

9999999-dev https://github.com/tkyk/cakephp-query-builder

CakePHP behavior to perform queries by Object-Oriented way

  Sources   Download

MIT

The Requires

 

by Takayuki Miwa

cakephp

28/12 2012

v2.0.1

2.0.1.0 https://github.com/tkyk/cakephp-query-builder

CakePHP behavior to perform queries by Object-Oriented way

  Sources   Download

MIT

The Requires

 

by Takayuki Miwa

cakephp