2017 © Pedro Peláez
 

cakephp-plugin orderly

Default ordering (behavior) for CakePHP 3

image

muffin/orderly

Default ordering (behavior) for CakePHP 3

  • Sunday, April 15, 2018
  • by ADmad
  • Repository
  • 8 Watchers
  • 18 Stars
  • 13,570 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 4 Versions
  • 12 % Grown

The README.md

Orderly

Build Status Coverage Total Downloads License, (*1)

Allows setting default order for your tables., (*2)

Install

Using Composer:, (*3)

composer require muffin/orderly

Then load the plugin using the console command:, (*4)

bin/cake plugin load Muffin/Orderly

What is does

Orderly allow you to set default ORDER clause for your table queries, similar to the functionality provided by Model::$order property of CakePHP 2.x., (*5)

Usage

Here's how you can add the Orderly behavior for your tables:, (*6)

// By default orders by display field of table.
$this->addBehavior('Muffin/Orderly.Orderly');

// Default ordering using specified field.
$this->addBehavior('Muffin/Orderly.Orderly', ['order' => $this->aliasField('field_name')]);

Value for order key can any valid value that \Cake\ORM\Query::order() takes. The default order clause will only be applied to the primary query and when no custom order clause has already been set for the query., (*7)

You can also configure the behavior to apply the default order based on required condition using callback option. The order will be applied if callback returns true:, (*8)

$this->addBehavior('Muffin/Orderly.Orderly', [
    'order' => ['Alias.field_name' => 'DESC'],
    'callback' => function (\Cake\ORM\Query $query, \ArrayObject $options, bool $primary) {
        //return a boolean
    }
]);

The behavior can also be configured with multiple orders which are applied based on return value of their respective callbacks:, (*9)

$this->addBehavior('Muffin/Orderly.Orderly', [
    [
        'order' => ['Alias.field_name' => 'DESC'],
        'callback' => function (\Cake\ORM\Query $query, \ArrayObject $options, bool $primary) {
            //return a boolean
        }
    ],
    [
        'order' => ['Alias.another_field'],
        'callback' => function (\Cake\ORM\Query $query, \ArrayObject $options, bool $primary) {
            //return a boolean
        }
    ],
]);

Patches & Features

  • Fork
  • Mod, fix
  • Test - this is important, so it's not unintentionally broken
  • Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
  • Pull request - bonus point for topic branches

To ensure your PRs are considered for upstream, you MUST follow the CakePHP coding standards., (*10)

Bugs & Feedback

http://github.com/usemuffin/orderly/issues, (*11)

License

Copyright (c) 2015-Present, Use Muffin and licensed under The MIT License., (*12)

The Versions

15/04 2018

dev-master

9999999-dev https://github.com/usemuffin/orderly

Default ordering (behavior) for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp muffin orderly

15/04 2018

1.1.0

1.1.0.0 https://github.com/usemuffin/orderly

Default ordering (behavior) for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp muffin orderly

15/04 2018

dev-cake-update

dev-cake-update https://github.com/usemuffin/orderly

Default ordering (behavior) for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp muffin orderly

05/02 2016

1.0.0

1.0.0.0 https://github.com/usemuffin/orderly

Default ordering (behavior) for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp muffin orderly