Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README updates #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions README-EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<p align="center">
x
</p>
<p align="center">
<i>Though the complexes, reach the destination.</i>
</p>

&nbsp;

# Davai

Davai(давай)is a routing class based on PHP, especially for RESTful and MVC web applications.

&nbsp;

# Features

1. Davai supports reversing paths.

2. You can customize the settings of routes.

3. Davai can handle requests in GET, POST, PUT, DELETE and PATCH methods.

4. You are able to name the route variables.


&nbsp;

# Getting Started

If you are running Apache server, please create a `.htacess` and copy the code below into it.
Next, please redirect ALL the requests to `index.php`. Thus Davai can receive all the requests and handle them.

```
RewriteEngine on
# PHP Extension To None-PHP Extensions
# RewriteRule ^ /%1 [R=301,NE,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/(.+)\.php[^\s]* [NC]
RewriteRule ^ - [R=404,L]

# Hide PHP Extensions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^.*$ index.php
```

&nbsp;

And, please construct a Davai class:

```php
$davai = new Davai();
```

&nbsp;

Time to write the routes. The `i` in `[i:userID]` means any integers, and `userID` is the variable name.

We have a document of this, please check it out later.

```php
$davai->get('/user/[i:userId]', function($userId)
{
echo 'Gotcha! You are reading the data of the user who has id ' . $userId . ' right?';
});
```

&nbsp;

Access `/user/123`, and you should get this shown on your screen:

```php
Gotcha! You are reading the data of the user who has id 123 right?
```

&nbsp;

# References

[dannyvankooten@AltoRouter](https://github.com/dannyvankooten/AltoRouter)

[Laravel - HTTP Routing](https://ihower.tw/blog/archives/6483)

[HTTP Verbs: 談 POST, PUT 和 PATCH 的應用](https://laravel.tw/docs/5.2/routing)

[Using HTTP Methods for RESTful Services](http://www.restapitutorial.com/lessons/httpmethods.html)

[Accessing Incoming PUT Data from PHP](http://www.lornajane.net/posts/2008/accessing-incoming-put-data-from-php)

[PHP detecting request type (GET, POST, PUT or DELETE)](http://stackoverflow.com/questions/359047/php-detecting-request-type-get-post-put-or-delete)
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,22 @@

# 教學

&nbsp;

# 範例

你需要先在你的 `.htacess` 新增這樣的規則,並將之後的網頁都導向 `index.php`,

如此一來才能夠在 `index.php` 中處理任何的路由事宜。
若你在使用 Apache Server,
請先新增一個 `.htacess` 檔案,並加入以下內容。
且請將所有 requests 都導向 `index.php`,
如此一來 Davai 才能接收所有請求並進行處理。

```
RewriteEngine on
# PHP Extension To None PHP Extension
# PHP Extension To None-PHP Extensions
# RewriteRule ^ /%1 [R=301,NE,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/(.+)\.php[^\s]* [NC]
RewriteRule ^ - [R=404,L]


# Hide Extension Of PHP
# Hide PHP Extensions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^.*$ index.php
Expand All @@ -63,9 +59,9 @@ $davai = new Davai();

&nbsp;

接下來開始撰寫路徑,其中的 `[i:userID]` 的 `i` 意思是任何數字,而 `userID` 則是變數名稱,
接下來開始撰寫路徑,其中的 `[i:userID]` 的 `i` 代表「任何數字」,而 `userID` 則代表「變數名稱」。

你可以再詳細的教學文件中找到說明
你稍後可以在詳細的教學文件中找到說明

```php
$davai->get('/user/[i:userId]', function($userId)
Expand Down Expand Up @@ -96,4 +92,4 @@ $davai->get('/user/[i:userId]', function($userId)

[Accessing Incoming PUT Data from PHP](http://www.lornajane.net/posts/2008/accessing-incoming-put-data-from-php)

[PHP detecting request type (GET, POST, PUT or DELETE)](http://stackoverflow.com/questions/359047/php-detecting-request-type-get-post-put-or-delete)
[PHP detecting request type (GET, POST, PUT or DELETE)](http://stackoverflow.com/questions/359047/php-detecting-request-type-get-post-put-or-delete)