Skip to content

JayParmar271/cakephp-magic-query

Repository files navigation

MagicQuery plugin for CakePHP

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.

About

Simple query builder made with CakePHP

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages