Skip to content

Commit 2ea86aa

Browse files
committed
✨ added route example
1 parent 5eb982e commit 2ea86aa

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

App/Routes/_app.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
/**@var Leaf\App $app */
3+
4+
$app->get("/", function () {
5+
echo view("index");
6+
});

App/Routes/index.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
/**@var Leaf\App $app */
44

5+
// You can break up routes into individual files
6+
require __DIR__ . "/_app.php";
7+
58
/*
69
|--------------------------------------------------------------------------
710
| Set up 404 handler
@@ -10,12 +13,24 @@
1013
| Create a handler for 404 errors
1114
|
1215
*/
13-
1416
$app->set404(function() {
15-
response()->headers->status(404);
17+
Leaf\Http\Headers::status(404);
1618
response()->page(views_path("errors/404.html", false));
1719
});
1820

21+
/*
22+
|--------------------------------------------------------------------------
23+
| Set up 500 handler
24+
|--------------------------------------------------------------------------
25+
|
26+
| Create a handler for error 500
27+
|
28+
*/
29+
$app->setErrorHandler(function() {
30+
Leaf\Http\Headers::status(500);
31+
response()->page(views_path("errors/500.html", false));
32+
});
33+
1934
/*
2035
|--------------------------------------------------------------------------
2136
| Set up Controller namespace
@@ -26,7 +41,3 @@
2641
|
2742
*/
2843
$app->setNamespace("\App\Controllers");
29-
30-
$app->get("/", function () {
31-
echo view("index");
32-
});

App/Views/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<h1>{{ getenv('APP_NAME') ?? "Leaf MVC" }}</h1>
1616
<p>
1717
This is the LeafMVC framework. A simple MVC framework built for
18-
<a href="https://leafphp.netlify.app" class="wynter text-green">Leaf PHP Framework</a>
18+
<a href="https://leafphp.netlify.app" class="text-green">Leaf PHP Framework</a>
1919
</p>
2020
</section>
2121
<section>

0 commit comments

Comments
 (0)