Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Default ordering for your CakePHP tables

License

NotificationsYou must be signed in to change notification settings

UseMuffin/Orderly

Repository files navigation

Build StatusCoverageTotal DownloadsLicense

Allows setting default order for your tables.

Install

UsingComposer:

composer require muffin/orderly

Then load the plugin using the console command:

bin/cake plugin load Muffin/Orderly

What is does

Orderly allow you to set defaultORDER clause for your table'sSELECT queries.

Usage

Here's how you can add theOrderly behavior for your tables:

// 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 fororder key can any valid value that\Cake\ORM\Query::orderBy() takes.The default order clause will only be applied to the primary query and when nocustom order clause has already been set for the query.

You can also configure the behavior to apply the default order based on requiredcondition usingcallback option. The order will be applied if callback returnstrue:

$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 basedon return value of their respective callbacks:

$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 oftheir 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 theCakePHP coding standards.

Bugs & Feedback

http://github.com/usemuffin/orderly/issues

License

Copyright (c) 2015-Present,Use Muffin and licensed underThe MIT License.


[8]ページ先頭

©2009-2025 Movatter.jp