diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-25 16:45:03 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-25 16:45:03 +0300 |
| commit | b594effb847b86fc6b1dae49d7948c46bba35e58 (patch) | |
| tree | 8c5a090cf8746870521324797762bb0ff14c8ae5 /public/app/routes/frontend.php | |
| parent | 65d07ba64d45c77d2db16272710ec5702b34d641 (diff) | |
| download | classroom-b594effb847b86fc6b1dae49d7948c46bba35e58.tar.gz classroom-b594effb847b86fc6b1dae49d7948c46bba35e58.tar.bz2 classroom-b594effb847b86fc6b1dae49d7948c46bba35e58.zip | |
alfa version; uploaded into test server (coder)
Diffstat (limited to 'public/app/routes/frontend.php')
| -rw-r--r-- | public/app/routes/frontend.php | 209 |
1 files changed, 103 insertions, 106 deletions
diff --git a/public/app/routes/frontend.php b/public/app/routes/frontend.php index f9e74db..33fe401 100644 --- a/public/app/routes/frontend.php +++ b/public/app/routes/frontend.php @@ -6,22 +6,45 @@ use app\controllers\cms\Course; use app\models\cms\Course_model; use app\extends\Cache_service; + // Home/Welcome -// --- -Route::add('/', function() { // echo 'Welcome!'; }); - Render::view('welcome', [ // cache categories (while retrieving) +//////////////////////////////////////////////////////////////////////////////// + +Route::add('/', function() { + Render::view('welcome', [ 'categories' => Cache_service::courses_struct()['tree'] ]); - // header('Location: /some/default/url', true, 302); + // need redirect?... header('Location: /some/default/url', true, 302); }); -// Error Pages -// --- -Route::notFound( function() { +// Error pages +//////////////////////////////////////////////////////////////////////////////// + +Route::notFound( function() { // 404 error page header("HTTP/1.0 404 Not Found"); Render::view('error/404', ['message' => 'nobody knows it (but you got a secret smile;)']); -}); // 404 +}); + + + +// Common content +//////////////////////////////////////////////////////////////////////////////// + + +Route::add('/course/([0-9]*)', // request course by course-id + function($id) { Course::course($id); } +); + +Route::add('/lesson/([0-9]*)', // request lesson by lesson-id + function($id) { Course::lesson($id); } +); + +Route::add('/serve/file/([0-9a-zA-Z-_\.\/]*)', // serve file by path + function ($path) { Course::serve_file($path); } // (also ?type= is sent) +); + + @@ -42,36 +65,8 @@ Route::notFound( function() { -// Resolve urls -// --- -- -- - - - -Route::add('/course/([0-9]*)', - function($id) { Course::course($id); } -); - -Route::add('/lesson/([0-9a-f]*)/([0-9a-zA-Z-_]*)', - function($ticket, $lesson) { Lesson::show([$lesson, $ticket]); } -); - -Route::add('/media/([0-9a-f]*)/([0-9a-zA-Z-_]*)/([0-9]*)/', - function($ticket, $type, $id) { Media::serve([$type, $id, $ticket]); } -); - - -// 4-th level paths belong to products -// --- -Route::add('/about/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', - function($a, $b, $c) { Page::show([$a, $b, $c]); } -); - - -// serve file -// --- -Route::add('/serve/file/([0-9a-zA-Z-_\.\/]*)', function ($path) { - Course::serve_file($path); -}); - -/** URL-format Proposal: +/** URL-format Proposals and common Route regex solutions * ----------------------------------------------------------------------------- * * Page (almost-static content): @@ -88,80 +83,82 @@ Route::add('/serve/file/([0-9a-zA-Z-_\.\/]*)', function ($path) { * * Category * /{category}/[ {subcategory}[ /{group}]] -Route::add('/([0-9a-zA-Z-_]*)', function($a) { Category::url([$a]); }; -Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Category::url([$a, $b]); }); -Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Category::url([$a, $b, $c]); }); - * ----------------------------------------------------------------------------- - */ - +# Route::add('/([0-9a-zA-Z-_]*)', function($a) { Category::url([$a]); }; +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Category::url([$a, $b]); }); +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Category::url([$a, $b, $c]); }); + * + * othet routes used in some user-cases -/* EXAMPLES (use it for brainsrtorming) +# Route::add('/lesson/([0-9a-f]*)/([0-9a-zA-Z-_]*)', +# function($ticket, $lesson) { Lesson::show([$lesson, $ticket]); } +# ); +# +# Route::add('/media/([0-9a-f]*)/([0-9a-zA-Z-_]*)/([0-9]*)/', +# function($ticket, $type, $id) { Media::serve([$type, $id, $ticket]); } +# ); + * + * 4-th level paths belong to products +# Route::add('/about/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', +# function($a, $b, $c) { Page::show([$a, $b, $c]); } +# ); + * + * + * OTHER EXAMPLES (use it for brainsrtorming) * ----------------------------------------------------------------------------- * - // Typical Use - // --- - Route::add('/art', function() { Art::blah(); }); - Route::add('/art/db', function() { Art::fromDatabase(); }); - Route::add('/art/([0-9]*)', function($id) { Art::getInfo($id); }); - - - // Get-Post route example - // --- - Route::add('/contact-form', function() { - echo '<form method="post"><input type="text" name="test" /><input type="submit" value="send" /></form>'; - }, 'get'); + * +# // Typical Use +# // --- +# Route::add('/art', function() { Art::blah(); }); +# Route::add('/art/db', function() { Art::fromDatabase(); }); +# Route::add('/art/([0-9]*)', function($id) { Art::getInfo($id); }); + * + * Get-Post route example +# Route::add('/contact-form', function() { +# echo '<form method="post"><input type="text" name="test" /><input type="submit" value="send" /></form>'; +# }, 'get'); Route::add('/contact-form', function() { echo 'Hey! The form has been sent:<br/>'; print_r($_POST); }, 'post'); - - - // Accept number as parameter - // --- - Route::add('/foo/([0-9]*)/bar', function($var1) { - // echo $var1.' is a number!'; + * + * Accept number as parameter +# Route::add('/foo/([0-9]*)/bar', function($var1) { +# // echo $var1.' is a number!'; echo "{$var1} is a number!"; - }); - - - // About pages - // --- - Route::add('/about/([0-9a-zA-Z-_]*)', function($page) { - InfoPage::render('about/'.page); - }); - - - // handle a request like: /foo/123/bar/3254-lefki-zaxari-marata-1kg - // where first-numeric-part of last-uri-section (3254) is the product number - // --- - Route::add('/foo/([0-9]*)/bar/([0-9]*)-([0-9a-zA-Z-_]*)', function($num, $id, $name) { - echo $num .' is some nomber, id = '. $id .' and label = '. $name; - }); - - - // handle a request like: /zaxares-glykantika/lefki-zaxari-year-2022-45678 - // where last-numeric-part of last-uri-section (45678) is the product number - // --- - Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)', - function($category, $subcategory, $group, $label, $id) { - Shop::product([$$category, $subcategory, $group, $label], $id); - }); - - - // last chance to resolve (some friendly url) - // --- - Route::add('/([0-9a-zA-Z-_]*)', function($a) { Resolve::uri([$a]); }); - Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Resolve::uri([$a, $b]); }); - Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Resolve::uri([$a, $b, $c]); }); - - - // Product page - // handle a request like: /pantopoleio/zaxares/lefki-zaxari/lefki-zaxari-year-2022-45678 - // where last-numeric-part of last-uri-section (45678) is the product number - // --- - Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)', - function($category, $subcategory, $group, $label, $id) { - Shop::product([$$category, $subcategory, $group, $label], $id); - }); -* ------------------------------------------------------------------------------ -*/ +# }); + * + * About pages +# Route::add('/about/([0-9a-zA-Z-_]*)', function($page) { +# InfoPage::render('about/'.page); +# }); + * + * handle a request like: /foo/123/bar/3254-lefki-zaxari-marata-1kg + * where first-numeric-part of last-uri-section (3254) is the product number +# Route::add('/foo/([0-9]*)/bar/([0-9]*)-([0-9a-zA-Z-_]*)', function($num, $id, $name) { +# echo $num .' is some nomber, id = '. $id .' and label = '. $name; +# }); + * + * handle a request like: /zaxares-glykantika/lefki-zaxari-year-2022-45678 + * where last-numeric-part of last-uri-section (45678) is the product number +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)', +# function($category, $subcategory, $group, $label, $id) { +# Shop::product([$$category, $subcategory, $group, $label], $id); +# }); + * + * last chance to resolve (some friendly url) +# Route::add('/([0-9a-zA-Z-_]*)', function($a) { Resolve::uri([$a]); }); +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Resolve::uri([$a, $b]); }); +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Resolve::uri([$a, $b, $c]); }); + * + * + * Product page + * handle a request like: /pantopoleio/zaxares/lefki-zaxari/lefki-zaxari-year-2022-45678 + * where last-numeric-part of last-uri-section (45678) is the product number +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)', +# function($category, $subcategory, $group, $label, $id) { +# Shop::product([$$category, $subcategory, $group, $label], $id); +# }); + * + * ------------------------------------------------------------------------------ + */ |
