jayparmar271/cakephp-magic-query

MagicQuery plugin for CakePHP

0.5.4 2020-12-14 19:18 UTC

This package is auto-updated.

Last update: 2024-05-16 02:58:34 UTC


README

Latest Stable Version Total Downloads License Tests PHPStan Check Coding Style Check

Simple query builder made with CakePHP

Requirements

  • CakePHP 3.5+

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require jayparmar271/cakephp-magic-query

Usage

  1. Add behavior in your table. (../src/Model/Table/UsersTable.php)
    $this->addBehavior('MagicQuery.Query');
  1. Use getRecord() to get single record.
    $this->Users->getRecord(['name'], ['id' => '1']);

To set default options:

  1. Create new config file and add your default options. (/config/magic_query.php)
return [
  'MagicQuery' => [
    'limit' => 2,
    'page' => 1,
    'orderBy' => ['id' => 'ASC'],
    'hydrate' => false,
    'validate' => true,
  ],
];
  1. Load into your bootstrap.php (/config/bootstrap.php)
/*
 * Load magic query file
 */
if (file_exists(CONFIG . 'magic_query.php')) {
    Configure::load('magic_query');
}

That's all. Enjoy!

You can find more examples here.

License

The MIT License. Please see License File for more information.