Skip to content

Instantly share code, notes, and snippets.

View aavrug's full-sized avatar
🏃‍♂️
Focusing

Gaurav Kumar aavrug

🏃‍♂️
Focusing
View GitHub Profile
#!/bin/sh
cd /home/aavrug/public_html/repos/project/app/Console
php ./cake Test
$validator
->requirePresence('confirm_password', 'create')
->notEmpty('confirm_password')
->add('confirm_password', ['compare' => ['rule' => ['compareWith', 'password']]]);
$currentTime = Time::now();
$previousDay = new Time('24 hours ago');
$this->paginate = [
'conditions' => [
'Devices.created between ? and ?' => [
$currentTime,
$previousDay
]
$previousDay = new Time('24 hours ago');
$this->paginate = [
'conditions' => [
'Devices.created >' => $previousDay
],
];
//$userIds is an array with key and value. the value is the user id
$this->paginate = [
'conditions' => ['Users.id' => $userIds->toArray()]
];
$this->paginate($this->Users);
public function findGrouped(Query $query, array $options)
{
$PostsTags = TableRegistry::get('PostsTags');
$Tags = TableRegistry::get('Tags');
$tagIds = $PostsTags->find('list', [
'conditions' => [
'PostsTags.tag_id' => $options['tags']
],
'fields' => [
@aavrug
aavrug / gist:261ae1b36bead005c750
Created September 17, 2015 05:45
Multiple record saving in Cake3
public function add()
{
$this->set('con',$this->Ctrl->get());
$permission = $this->Permissions->newEntity();
if ($this->request->is('post')) {
foreach ($this->request->data as $data) {
$permission = $this->Permissions->patchEntity($permission, $data);
$this->Permissions->save($permission);
}
}
view
<?= $this->Form->create($permission,['class' => 'form-horizontal form-horizontal form-bordered','data-parsley-validate' => "true", 'name' => "demo-form"]) ?>
<?php for ($i=0; $i < 5; $i++) { ?>
<div class="form-group">
<label class="col-md-3 control-label">Name</label>
<div class="col-md-9">
<?php echo $this->Form->input("$i.name", ['class' => 'form-control' ,'label' => false, 'placeholder' => 'Enter Name']); ?>
</div>
</div>
if (empty($status->toArray())) {
$singlePost = $this->Posts->find('all', ['conditions' => ['type' => 'published', 'id' => 21]]);
}
$allPosts = $this->Posts->find('all', ['conditions' => ['type' => 'published', 'id NOT IN' => [0, 21]]]);
$posts = $singlePost->append($allPosts);
debug($posts->toArray());exit;
public function order_by_comments()
{
$posts = $this->paginate($this->Posts, [
'sortWhitelist' => [
'id',
'title',
'total',
],
'fields' => [
'id',