elstc/cakephp-restore-query

用于 CakePHP 3 的查询字符串保留和恢复插件

安装: 50

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:cakephp-plugin

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

This package is auto-updated.

Last update: 2024-08-29 04:43:09 UTC


README

Software License Build Status Codecov Latest Stable Version

此插件提供了一个组件,可以在切换到另一页面后仍然恢复列表、搜索页面等条件。

要求

  • CakePHP 3.x

安装

您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。

安装 composer 包的推荐方法是

composer require elstc/cakephp-restore-query

将以下行添加到您的应用程序的 config/bootstrap.php 文件中

use Cake\Core\Plugin;
Plugin::load('Elastic/RestoreQuery');

使用方法

保留查询字符串

使用您控制器的 initialize 方法加载组件。

class AppController extends Controller
{
    public function initialize()
    {
        $this->loadComponent('Elastic/RestoreQuery.RestoreQuery', [
            'actions' => ['index', 'search'], // List of actions to record query string
        ]);
    }
}

组件将自动保存目标动作的查询字符串。

恢复保存的查询字符串

通过在模板中创建如下链接,组件将调用保存的查询字符串并重定向到目标页面。

    <?=
    $this->Html->link('link text', [
        'action' => 'index',
        '?' => ['_restore' => true], // NOTE: _restore=true, the component will restore the saved query.
    ]);
    ?>

Elastic/RestoreQuery.RestoreQueryComponent 选项

actions

记录查询字符串的动作列表。

默认: ['index', 'search']

sessionKey

用于保存查询字符串的会话键名称

默认: 'StoredQuerystring'

restoreKey

恢复动作的查询字符串名称。

默认: '_restore'

redirect

在恢复查询字符串时进行重定向。

默认: true