PHPackages                             adods/page-marker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. adods/page-marker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

adods/page-marker
=================

Library for saving CRUD list filter in request query

1.0(6y ago)0231MITPHPPHP &gt;=7.0.0

Since Nov 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/adods/page-marker)[ Packagist](https://packagist.org/packages/adods/page-marker)[ RSS](/packages/adods-page-marker/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (1)

Page Marker
===========

[](#page-marker)

A Simple Library for remembering/recording URL Query String used for filtering list

Installation
------------

[](#installation)

Via Composer:

```
composer require adods/page-marker

```

or just download the file manually and put in your lib directory

Requirement
-----------

[](#requirement)

`PHP >= 7.0` and PHP Session enabled

Simple Usage
------------

[](#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()`

[](#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
-------------------

[](#main-settingssetup)

Settings below should be set BEFORE `init()`.

### Session Name:

[](#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:

[](#change-base-url)

```
$om->setUrl('http://newurl.test/path')
```

Any query string will be omitted.

### Change base data source

[](#change-base-data-source)

```
$pm->setBase($somearray);
```

More Function
-------------

[](#more-function)

### Add/Change data

[](#addchange-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

[](#excluding-data)

```
$pm->except('nothisone');
// or
$pm->except(['notme', 'alsonotme']);
```

### Remember Options

[](#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

[](#manually-forgetreset)

```
$pm->forget();
```

### Get Forget/Reset URL

[](#get-forgetreset-url)

```
$pm->getResetUrl();
```

Full Example
------------

[](#full-example)

```
require_once './vendor/autoload.php';

use Adods\PageMarker\PageMarker;

$pm = new PageMarker;

$pm->init();

$pm->remember();

var_dump($pm->getBase());
?>

    Base URL:
