From 4063face5fb3afe6ba575bfc3ea5d1beb3b67b68 Mon Sep 17 00:00:00 2001 From: Birkhoff Lee Date: Wed, 26 Oct 2016 22:27:25 +0800 Subject: [PATCH] README updates --- README-EN.md | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 24 ++++++-------- 2 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 README-EN.md diff --git a/README-EN.md b/README-EN.md new file mode 100644 index 0000000..40bf363 --- /dev/null +++ b/README-EN.md @@ -0,0 +1,93 @@ +

+ x +

+

+ Though the complexes, reach the destination. +

+ +  + +# Davai + +Davai(давай)is a routing class based on PHP, especially for RESTful and MVC web applications. + +  + +# 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. + + +  + +# 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 +``` + +  + +And, please construct a Davai class: + +```php +$davai = new Davai(); +``` + +  + +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?'; +}); +``` + +  + +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? +``` + +  + +# 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) diff --git a/README.md b/README.md index ef7b1bd..40955ae 100644 --- a/README.md +++ b/README.md @@ -28,26 +28,22 @@ # 教學 -  - -# 範例 - -你需要先在你的 `.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 @@ -63,9 +59,9 @@ $davai = new Davai();   -接下來開始撰寫路徑,其中的 `[i:userID]` 的 `i` 意思是任何數字,而 `userID` 則是變數名稱, +接下來開始撰寫路徑,其中的 `[i:userID]` 的 `i` 代表「任何數字」,而 `userID` 則代表「變數名稱」。 -你可以再詳細的教學文件中找到說明。 +你稍後可以在詳細的教學文件中找到說明。 ```php $davai->get('/user/[i:userId]', function($userId) @@ -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) \ No newline at end of file