elstc/cakephp-restore-query

Retaining and Restoring query strings plugin for CakePHP 3

Installs: 50

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

v0.5.1 2018-05-09 03:50 UTC

This package is auto-updated.

Last update: 2024-03-29 03:44:38 UTC


README

Software License Build Status Codecov Latest Stable Version

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.

Requirements

  • CakePHP 3.x

Installation

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');

Usage

Retaining query string

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.

Restore saved query string

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.
    ]);
    ?>

Elastic/RestoreQuery.RestoreQueryComponent Options

actions

List of actions to record the query string.

default: ['index', 'search']

sessionKey

Name of session key for query string saving

default: 'StoredQuerystring'

restoreKey

Name of the query string for restore action.

default: '_restore'

redirect

Redirect when restoring the query string.

default: true