Skip to content

Commit

Permalink
Merge pull request #229 from FriendsOfCake/josegonzalez-patch-1
Browse files Browse the repository at this point in the history
docs: clarify how to use the ViewSearchListener
  • Loading branch information
josegonzalez authored Jan 21, 2018
2 parents 7e7ca8b + 4531c17 commit ac6d8a0
Showing 1 changed file with 52 additions and 20 deletions.
72 changes: 52 additions & 20 deletions docs/_partials/pages/index/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,33 @@ to be installed and filters configured for your model using the search manager.
.. code-block:: php
<?php
class SamplesController extends AppController {
namespace App\Controller;
use App\Controller\AppController;
public function index() {
$this->Crud->addListener('Crud.Crud');
$this->Crud->addListener('Crud.ViewSearch', [
class SamplesController extends AppController
{
public function initialize()
{
parent::initialize();
// Enable PrgComponent so search form submissions
// properly populate querystring parameters for the SearchListener
$this->loadComponent('Search.Prg', [
'actions' => [
'index',
],
]);
}
public function index()
{
// Enable the SearchListener
$this->Crud->addListener('search', 'Crud.Search', [
// The search behavior collection to use. Default "default".
'collection' => 'admin',
]);
// Enable the ViewSearch listener
$this->Crud->addListener('viewSearch', 'CrudView.ViewSearch', [
// Indicates whether is listener is enabled.
'enabled' => true,
Expand Down Expand Up @@ -41,7 +63,7 @@ to be installed and filters configured for your model using the search manager.
]
]);
$this->Crud->execute();
return $this->Crud->execute();
}
}
Expand All @@ -50,18 +72,28 @@ Here's an e.g. of how configure filter controls options through search manager i
.. code-block:: php
<?php
// Samples::initialize()
$this->searchManager()
->useCollection('backend')
->add('q', 'Search.Like', [
'field' => ['title', 'body'],
'form' => [
'data-foo' => 'bar'
]
])
->add('category_id', 'Search.Value', [
'form' => [
'type' => 'select',
'class' => 'no-selectize'
]
]);
namespace App\Model\Table;
use Cake\ORM\Table;
class SamplesTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->addBehavior('Search.Search');
$this->searchManager()
->useCollection('default')
->add('q', 'Search.Like', [
'field' => ['title', 'body'],
'form' => [
'data-foo' => 'bar'
]
])
->add('category_id', 'Search.Value', [
'form' => [
'type' => 'select',
'class' => 'no-selectize'
]
]);
}
}

0 comments on commit ac6d8a0

Please sign in to comment.