This plugin provides a component that makes it possible to restore the conditions in the list, search page, etc. even after transitioning to another page.
- CakePHP 3.x
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require elstc/cakephp-restore-query
Add the following line to your application config/bootstrap.php
:
use Cake\Core\Plugin;
Plugin::load('Elastic/RestoreQuery');
Load the component with your controller's initialize
method.
class AppController extends Controller
{
public function initialize()
{
$this->loadComponent('Elastic/RestoreQuery.RestoreQuery', [
'actions' => ['index', 'search'], // List of actions to record query string
]);
}
}
The component automatically saves the Query string for the target action.
By creating a link in the template as follows, the component will call the saved query string and redirect to the target page.
<?=
$this->Html->link('link text', [
'action' => 'index',
'?' => ['_restore' => true], // NOTE: _restore=true, the component will restore the saved query.
]);
?>
List of actions to record the query string.
default: ['index', 'search']
Name of session key for query string saving
default: 'StoredQuerystring'
Name of the query string for restore action.
default: '_restore'
Redirect when restoring the query string.
default: true