You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my unstable version of file-based routing, inspired by Javascript Libraries/Frameworks, to make my project's URL tiny-little-bit-beautiful even my backend is an instant legacy code.
3
+
4
+
### Sooo @frozeeen, again what's this?
5
+
Well, here you go
6
+
```python
7
+
https://yourawesome.web/post?id=ABCDEFG12345
8
+
to
9
+
https://yourawesome.web/post/ABCDEFG12345
10
+
```
11
+
12
+
### Installation
13
+
1. Simply clone this project into your machine.
14
+
2. Update the config inside the `index.php`.
15
+
3. and presto! all set.
16
+
17
+
### Structure
18
+
The structure is very simple
19
+
```python
20
+
pages # This is where your pages will live
21
+
assets # Maybe some of your CSS, JS and other assets
22
+
index.php # And this is where some tiny-little-bit magic polynomial time happens, it's the router
23
+
.htaccess # We don't talk about .htaccess -Dani
24
+
```
25
+
26
+
### How to use this?
27
+
To use this, let's head into `pages` and make some files.
28
+
29
+
#### Static routing
30
+
```python
31
+
Path: pages/your-awesome-page.php
32
+
URL: http://website.com/your-awesome-page
33
+
```
34
+
35
+
#### Dynamic routing
36
+
To create a dynamic url like `https://website.com/post?id=YOURPOSTID` we're going to do it like this.
37
+
```python
38
+
# Create a file
39
+
Path: pages/post/[id].php
40
+
URL: https://website.com/post/YOURPOSTID
41
+
```
42
+
and to access the value in our code, it's just like normal `$_GET`, the name between the brackets `[]` is the parameter name (they call this `slug`).
43
+
```php
44
+
Showing post ID: <?php echo $_GET['id']; ?>
45
+
```
46
+
47
+
#### Nexted Dynamic routing
48
+
We can also create a folder to become our slug.
49
+
```python
50
+
# Create folder an file
51
+
Path: pages/post/[id]/edit.php
52
+
URL: pages/post/YOURPOSTID/edit
53
+
```
54
+
So the file structure will look like this, and let's add additional files.
0 commit comments