jayparmar271 / cakephp-magic-query
MagicQuery plugin for CakePHP
Installs: 26
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 2
Open Issues: 1
Type:cakephp-plugin
Requires
- cakephp/cakephp: ^3.5
- symfony/options-resolver: ^5.2
Requires (Dev)
- cakephp/cakephp-codesniffer: ^3.0
- phpstan/phpstan: ^0.12.60
- phpunit/phpunit: ^5.7.14|^6.0
This package is auto-updated.
Last update: 2025-04-16 05:06:35 UTC
README
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
- 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']);
To set default options:
- 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.
License
The MIT License. Please see License File for more information.