Skip to content

Instantly share code, notes, and snippets.

@edvakf edvakf/rt-router.php
Last active Aug 29, 2015

Embed
What would you like to do?
フレームワークではなくライブラリとして使うPHPのルーター案
<?php
if ($m = RT::get('/works/:id' /*pathパターン*/, [':id:uint' /*pathのパラメータ*/])) {
getWorks($m[':id']);
} else if ($m = RT::get('/works/', ['page:uint:1' /*GETパラメータ。デフォルト1*/, 'type:string:' /*GETパラメータ。デフォルト空文字*/, 'tags:string[]' /*GETパラメータ。配列のみ受け取る。デフォルトは空配列?*/])) {
getWorks($m['page'], $m['type'], $m['tags']);
} elseif ($m = RT::post('/works/', [] /*pathパラメータとGETパラメータは処理しない*/, ['type:string'] /*POSTパラメータ*/)) {
postWork($m['type']);
} else {
// not found
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.