adods/page-marker
Composer 安装命令:
composer require adods/page-marker
包简介
Library for saving CRUD list filter in request query
README 文档
README
A Simple Library for remembering/recording URL Query String used for filtering list
Installation
Via Composer:
composer require adods/page-marker
or just download the file manually and put in your lib directory
Requirement
PHP >= 7.0 and PHP Session enabled
Simple Usage
Include the library to your file, create instance, init() and remember().
Use forget() to reset.
require "path/to/lib/src/PageMarker.php"; // or if you're using composer require "path/to/vendor/autoload.php"; use Adods\PageMarker\PagerMarker; // Make sure there's no output before doing this $pm = new PageMarker; // Setup default setting and redirect when condition are met $pm->init(); // Start recording $pm->remember();
init()
By default, init() will generate default name from current URL Path,
lowercased, then replace slashes '/', dots '.', stripes '-', and spaces
' ' to underscore _. Set default url to current url without it's query
string. And use the content of $_GET Super Global variable as base data. But,
it can be changed.
After default properties are set, then it will check if redirect to the last state is met or just go on with the process.
The conditions are:
- If the base data contain a reset key element, then the remembered session will be erased and will be redirected to the base URL.
- If the base data is not empty, then process will continue normally
- Then it will check the session for existing data.
- If session data is empty, then process will continue normally
- Lastly, it will redirect to the base URL with the data from session as Query String parameters
Main Settings/Setup
Settings below should be set BEFORE init().
Session Name:
Name is used as part of the session key.
$pm->setName('new_name');
Name should be easy to read and descriptive about the list and also array key
friendly. And any characters mentioned above will be replaced with underscore
'_'
Change base URL:
$om->setUrl('http://newurl.test/path')
Any query string will be omitted.
Change base data source
$pm->setBase($somearray);
More Function
Add/Change data
$pm->add('newkey', 'newvalue'); // or $pm->add([ 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3' ]);
Using array as parameter will merge the array with current data
Excluding data
$pm->except('nothisone'); // or $pm->except(['notme', 'alsonotme']);
Remember Options
Data can also overrided from remember() method.
$pm->remember([ 'shouldbeme' => 'yes' ]);
By default, the given parameter will REPLACE the current base data. To add them,
you can use PageMarker::OVERRIDE_APPEND constant as second parameter.
$pm->remember([ 'letmejoin' => 'yes' ], PageMarker::OVERRIDE_APPEND);
Manually Forget/Reset
$pm->forget();
Get Forget/Reset URL
$pm->getResetUrl();
Full Example
require_once './vendor/autoload.php'; use Adods\PageMarker\PageMarker; $pm = new PageMarker; $pm->init(); $pm->remember(); var_dump($pm->getBase()); ?> <div> Base URL: <?php echo $pm->getUrl(); ?> </div> <a href="<?php echo $pm->getResetUrl(); ?>">Reset</a>
Try to add parameters to the URL. Everytime the base URL accessed it will automatically redirect with last state URL with Query String Parameters. Click on Reset link to clear all the saved data.
adods/page-marker 适用场景与选型建议
adods/page-marker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 adods/page-marker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adods/page-marker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-28