PHP code example of itosho / easy-query
1. Go to this page and download the library: Download itosho/easy-query library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
itosho / easy-query example snippets
$this->Tags = TableRegistry::getTableLocator()->get('Tags');
$this->Tags->addBehavior('Itosho/EasyQuery.Upsert', [
'uniqueColumns' => ['name'],
'updateColumns' => ['description', 'modified'],
]);
$data = [
'name' => 'cakephp',
'description' => 'php web framework',
];
$entity = $this->Tags->newEntity($data);
$this->Tags->upsert($entity);
$this->Tags = TableRegistry::getTableLocator()->get('Tags');
$this->Tags->addBehavior('Itosho/EasyQuery.Upsert', [
'updateColumns' => ['description', 'modified'],
]);
$data = [
[
'name' => 'cakephp',
'description' => 'php web framework',
],
[
'name' => 'rubyonrails',
'description' => 'ruby web framework',
]
];
$entities = $this->Tags->newEntities($data);
$this->Tags->bulkUpsert($entities);
$this->Articles = TableRegistry::getTableLocator()->get('Articles');
$this->Articles->addBehavior('Itosho/EasyQuery.Insert');
$data = [
[
'title' => 'First Article',
'body' => 'First Article Body',
'published' => '1',
],
[
'title' => 'Second Article',
'body' => 'Second Article Body',
'published' => '0',
]
];
$entities = $this->Articles->newEntities($data);
$this->Articles->bulkInsert($entities);
$this->Articles = TableRegistry::getTableLocator()->get('Articles');
$this->Articles->addBehavior('Itosho/EasyQuery.Insert');
$data = [
'title' => 'New Article?',
'body' => 'New Article Body?',
];
$entity = $this->Articles->newEntity($data);
$condition = ['title' => 'New Article?'];
$this->Articles->insertOnce($entities);
$this->Articles = TableRegistry::getTableLocator()->get('Articles');
$this->Articles->addBehavior('Itosho/EasyQuery.Insert');
$data = [
'title' => 'New Article',
'body' => 'New Article Body',
];
$entity = $this->Articles->newEntity($data);
$this->Articles->insertOnce($entities);
// default value is true
$this->Articles->addBehavior('Itosho/EasyQuery.Insert', [
'event' => ['beforeSave' => false],
]);