PHP code example of codekanzlei / cake-list-filter
1. Go to this page and download the library: Download codekanzlei/cake-list-filter 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/ */
codekanzlei / cake-list-filter example snippets
public function getListFilters($action) {
$filters = [];
if ($action == 'index') {
$filters = [
'fields' => [
'Posts.title' => [
'searchType' => 'wildcard',
'inputOptions' => [
'label' => __('posts.title')
]
],
'Posts.author_id' => [
'searchType' => 'select',
'options' => $this->Posts->Authors->find('list'),
'inputOptions' => [
'label' => __('posts.author')
]
]
]
];
}
return $filters;
}
public function index()
{
$this->paginate['contain'] = ['Authors'];
$posts = $this->paginate($this->Posts);
$this->set('posts', $posts);
}
<?= $this->ListFilter->renderFilterbox()
public $components = [
'ListFilter.ListFilter' => [
'searchTermsConjunction' => 'OR'
]
];
public function index()
{
$this->paginate['contain'] = ['Users'];
$query = $this->Users->query();
if (isset($this->paginate['conditions']['Users.group_id'])) {
$groupId = $this->paginate['conditions']['Users.group_id'];
unset($this->paginate['conditions']['Users.group_id']);
$query->matching('Groups', function ($q) use ($groupId) {
return $q->where(['Group.id' => $groupId]);
});
}
$users = $this->paginate($query);
$this->set(compact('users'));
}
<?= $this->ListFilter->openForm();