Simple query builder made with CakePHP
- CakePHP 3.5+
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
- Add behavior in your table. (../src/Model/Table/UsersTable.php)
$this->addBehavior('MagicQuery.Query');
- Use getRecord() to get single record.
$this->Users->getRecord(['name'], ['id' => '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,
],
];- 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.
The MIT License. Please see License File for more information.