0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

マイクロフレームワーク Flight の簡単なルーティング 

Last updated at Posted at 2018-07-30
  1. まず、ソースをクローンします。
git clone https://github.com/mikecao/flight.git
  1. そのまま動かしてみます。
cd flight
php -S 0.0.0.0:9000

ブラウザーで、http://localhost:9000/ にアクセスします。
flight_jul3001.png

  1. index.php を改造します。
index.php
<?php
// -----------------------------------------------------------------
require 'flight/Flight.php';

require 'application/views/greeting.php';


Flight::route('/',array('Greeting','hello'));
Flight::route('/morning',array('Greeting','morning'));
Flight::route('/afternoon',array('Greeting','afternoon'));
Flight::route('/evening',array('Greeting','evening'));


Flight::start();
// -----------------------------------------------------------------
  1. フォルダーの作成
mkdir application
mkdir application/views
  1. greeting.php の作成
application/views/greeting.php
<?php
// -----------------------------------------------------------------
class Greeting {
    public static function hello() {
        echo '*** Greeting ***<p />';
        echo '*** 挨拶 ***<p />';
        echo '*** Jul/30/2018 *** AM 10:37<p />';
    }

// -----------------------------------------------------------------
    public static function morning() {
        echo '*** Good Morning ***<p />';
        echo '*** おはよう ***<p />';
        echo '*** Jul/30/2018 *** AM 10:40<p />';
    }
// -----------------------------------------------------------------
    public static function afternoon() {
        echo '*** Good Afternoon ***<p />';
        echo '*** こんにちは ***<p />';
        echo '*** Jul/30/2018 *** AM 10:45<p />';
    }
// -----------------------------------------------------------------
    public static function evening() {
        echo '*** Good Evening ***<p />';
        echo '*** 今晩は ***<p />';
        echo '*** Jul/30/2018 *** AM 10:55<p />';
    }
// -----------------------------------------------------------------
}
// -----------------------------------------------------------------
?>
  1. サーバーを再び起動して、アクセスしてみます。

http://localhost:9000/
flight_jul3002.png

http://localhost:9000/morning
flight_jul3003.png

http://localhost:9000/afternoon
http://localhost:9000/evening

次のバージョンで確認しました。

$ php --version
PHP 8.0.8 (cli) (built: Oct 26 2021 11:42:42) ( NTS )``text
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?