mecha-cms / mecha

Minimalist content management system.

Home Page:https://mecha-cms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pagination Specification for Version 2.2.2

taufik-nurrohman opened this issue · comments

Generic Pages’ URL Path

  • http://127.0.0.1/blog

Pages’ URL Path (Paginated)

  • http://127.0.0.1/blog/2

Generic Page’s URL Path

  • http://127.0.0.1/blog/foo-bar

Tags’ Page (Always Paginated)

  • http://127.0.0.1/blog/tag/foo-bar

Tags’ Page (Paginated)

  • http://127.0.0.1/blog/tag/foo-bar/2

Next Extension (Paginated)

  • http://127.0.0.1/blog/foo-bar/page/2

Comment Extension (Paginated)

  • http://127.0.0.1/blog/foo-bar/comment/2

Pattern

path/key(/value)?(/offset)?
  • path → URL path that maps to a page that exists.
  • key → Context which has a default value set to true; example: /article/foo-bar/comment/1 would be extracted to something like ["article/foo-bar","comment=true",1]
  • key/value → Context which has a value set to value; example: /article/tag/foo/1 would be extracted to something like ["article","tag=foo",1]

Route

  • */:i, *
  • */comment/:i, */comment
  • */tag/:name/:i, */tag/:name

TODO

  • Remove $url->i property.

    This URL part should be in the $url->path so that it becomes standard and so any URL string could be parsed easily with parse_url() function without extra process to extract the page offset from URL path.

  • Remove $url->d property.

    Maybe we could determine context to the URL constructor so that we could set custom base URL based on place where Mecha was installed:

    $r = 'http://127.0.0.1/mecha/foo/bar/2';
    $url = new URL($r, '/mecha');
    
    echo $url; // `http://127.0.0.1/mecha`
    echo $url->path; // `/foo/bar/2`

Since v2.2.1: First parameter to replace the URL separator. Second parameter to replace the URL path parts.

$url['path']; // `foo/bar/1`
$url->path; // `/foo/bar/1`
$url->path("\\"); // `\foo\bar\1`
$url->path('/', ['baz', 'qux']); // `/baz/qux/1`

To replace the page offset:

$url->path; // `/foo/bar/1`

$count = substr_count($url['path'], '/') + 1;
$url->path('/', [$count => 4]); // `/foo/bar/4`

Nah, maybe I will keep it that way. Extra parameters in constructor is enough.

new URL(string $in, string $d = null, int $i = 0);

It is now possible to refresh the whole URL data by updating its data partially. Previously, we will need to do this kind of thing to make sure everything properly synchronized:

$url = new URL('http://127.0.0.1');
$url->path = '/foo/bar';
$url->i = '/4';
$url->clean .= '/foo/bar'; // :(
$url->current .= '/foo/bar/4'; // :(

var_dump($url);

Now you could just do this and the others will be automatically synchronized:

$url = new URL('http://127.0.0.1');
$url->path = '/foo/bar';
$url->i = '/4';

echo $url->current; // `http://127.0.0.1/foo/bar/4`

Magic methods aren’t that bad.