F3:優れた機能を備えた小さなPHPフレームワーク





私が最近出会った軽量のPHPフレームワークに注意を喚起したいと思います。



Fat-Freeは、有名なSinatra Rubyフレームワークに似ています。 Fat-Freeの作者は、ミニマリズムとコードの清潔さに夢中になっており、さまざまなアプリケーションを開発するためのこのシンプルなフレームワークにプラスの影響を与えています。



Fat-Freeは1つのファイルで構成され、重量はわずか55KBです。 同時に、フレームワークには次の機能があります:特定の非常に便利なテンプレートエンジン、柔軟なキャッシング、自動スパム保護、単体テスト用の統合ツール、コードプロファイラー。



非常に小さくて高速なので、Webサーバーのトラフィックを制御するためにも使用できます。



また、ホットリンクやDoS攻撃からアプリケーションを保護する唯一のフレームワークです。





初心者でもプロのPHPプログラマでも、Fat-Freeは使いやすく、同時に強力です。 インストールや明確なディレクトリ構造は必要ありません。 このフレームワークを使用すると、オブジェクト指向スタイルと手続きスタイルの両方でアプリケーションを作成できます。 Fat-Free哲学とMVCアーキテクチャへのアプローチは、構造コンポーネントを最小限に抑え、複雑さを回避し、コードの優雅さ、アプリケーションのパフォーマンス、プログラマの生産性のバランスを保つよう努めています。



Fat-Freeには、フレームワークの機能を拡張するためのプラグインが付属しています。







メインページにグリーティングを表示するファイルは次のとおりです。

  1. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { echo 'Hello, world!' ; } F3 :: run ( ) ;



  2. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { echo 'Hello, world!' ; } F3 :: run ( ) ;



  3. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { echo 'Hello, world!' ; } F3 :: run ( ) ;



  4. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { echo 'Hello, world!' ; } F3 :: run ( ) ;



  5. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { echo 'Hello, world!' ; } F3 :: run ( ) ;



  6. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { echo 'Hello, world!' ; } F3 :: run ( ) ;





仕事を始める



注意:フレームワークが機能するには、少なくとも5.3のPHPバージョンと、インストールおよび構成されたmod_rewriteが必要です!



このガイドを煩雑にしないために、単純なアプリケーション(ゲストブック)のデザインといくつかの明らかな機能を書くことを避けることにしました。



まず、あなたにとって都合の良い方法でデータベースを作成します。 SQLite / MySQLとMongoDBの両方がデータベースとして機能します。 アプリケーションは指数関数的でシンプルなので、SQLiteを選択します。



guestbook.sqliteデータベースには、 idauthorcommentの各フィールドを含むコメントが 1つしかありません。



アプリケーションのルートにindex.phpファイルを作成し、htaccessファイルの名前を.htaccessに変更します(前にドットを付けます)。



次に、index.phpのメインで唯一のフレームワークファイルを接続し、データベースへのパスを決定します。

  1. require_once 'F3 / F3.php' ; //フレームワークを接続します
  2. F3 :: set 'DB' array 'dsn' => 'sqlite:guestbook.sqlite' ; / *データベースへの接続の初期化。
  3. 注意:バージョンsqlite = 2の場合、DSNは次のようになります。
  4. 'dsn' => 'sqlite2:guestbook.sqlite'
  5. * /


Hello Worldメッセージが表示される最初の例では、ルート(パス)を処理する方法の1つを見ました。 実際、それらのいくつかがあり、自由に選択できます:



1.ルートハンドラー関数-最初の例のように。 F3 :: rote()メソッドの2番目のパラメーターは、どこでも同じファイルで記述する関数です



2. F3 :: rote()メソッドの2番目のパラメーターの無名関数:

  1. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , function ( ) { echo 'Hello, world!' ; } ) ; F3 :: run ( ) ;



  2. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , function ( ) { echo 'Hello, world!' ; } ) ; F3 :: run ( ) ;



  3. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , function ( ) { echo 'Hello, world!' ; } ) ; F3 :: run ( ) ;



  4. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , function ( ) { echo 'Hello, world!' ; } ) ; F3 :: run ( ) ;



  5. require_once 'path/to/F3.php' ; F3 :: route ( 'GET /' , function ( ) { echo 'Hello, world!' ; } ) ; F3 :: run ( ) ;





3.同じ2番目のパラメーターの静的クラスメソッド:

  1. require_once 'path / to / F3.php' ;
  2. クラス MyClass {
  3. public static function hello {
  4. エコー 「こんにちは、世界!」 ;
  5. }
  6. }
  7. F3 :: route 'GET /' 'MyClass :: hello' ;
  8. F3 :: run ;


4.通常のクラスメソッド:

  1. require_once 'path / to / F3.php' ;
  2. クラス MyClass {
  3. パブリック 関数 hello {
  4. エコー 「こんにちは、世界!」 ;
  5. }
  6. }
  7. $ test = new MyClass ;
  8. F3 :: route 'GET /' array $ test 'hello' ;
  9. F3 :: run ;


5.最後に、ハンドラーは、他のそのようなファイルとともに任意のディレクトリにある別のファイルである場合があります。 ハンドラファイルのあるディレクトリは、index.phpファイルの先頭で宣言する必要があります。その後、ルートハンドラファイルを呼び出すことができます。

  1. //index.php:
  2. <?php
  3. require_once 'path / to / F3.php' ;
  4. F3 :: set 'IMPORTS' 'yourpath' ;
  5. F3 :: route 'GET /' yourfile ;
  6. F3 :: run ;
  7. //yourpath/yourfile.php
  8. <?php echo 'Hello World!' ; ?>


ゲストブックの開発を続けています。 index.phpファイルで、プラグインファイルへのパスを追加します。これは、Fat-Freeに付属するAxonというORMを使用するために必要です。

  1. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; /* . autoload. .*/ F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ;



  2. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; /* . autoload. .*/ F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ;



  3. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; /* . autoload. .*/ F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ;



  4. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; /* . autoload. .*/ F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ;



  5. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; /* . autoload. .*/ F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ;





上記のいずれかの方法でホームページ要求処理を追加します。 最も視覚的なものとして最初のものを選択します。

  1. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  2. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  3. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  4. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  5. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  6. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  7. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  8. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  9. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  10. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  11. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  12. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  13. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }



  14. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // foreach ( $all_comments as $comment ) { /* . , . */ echo ': ' . $comment [ 'author' ] . '<br />' ; echo ': ' . $comment [ 'comment' ] . '<br /><br />' ; } }





よくここに。 コメントの表示はすでに機能しています。 追加に進むことができます。 しかし、最初に、テンプレートについて少しお話したいと思います。



テンプレートへのパスは、他のテンプレートと同じ方法で設定されます。

  1. F3 :: set ( 'GUI' , ' ' ) ;





特定のテンプレートに変数を渡すことはできません。 Fat-Freeの変数は、アプリケーション全体に設定されます。 これは、すでによく知られている静的メソッドを使用して行われます。

  1. F3 :: set ( '' , '' ) ;





現在、この変数はどこでも使用できます。 HTMLコードおよび文字列形式では、その値は{@変数}、PHPコードでは次のように呼び出されます。

  1. F3 :: get 'variable' ;


テンプレートを呼び出すには、serveメソッドを使用します。

  1. F3 :: serve ( 'template.html' ) ;





したがって、私のアプリケーションは次のようになります。

  1. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  2. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  3. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  4. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  5. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  6. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  7. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  8. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  9. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  10. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  11. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  12. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  13. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  14. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  15. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  16. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>



  17. //index.php: <?php require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; // comments $all_comments = $comments -> find ( ) ; // F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } ?> <!-- template.html --> <F3:repeat key= “{@key}” index="{@comment}" group="{@comments}"> <p>{@comment.id}</p> </F3:repeat>





この例は、Fat-Freeテンプレートエンジンの動作を示しています。ループでは、すべてのコメントを含む変数が処理されます。



次のステップは、コメントフォームをページに追加することです。 これを行うには、まずテンプレートフォルダーにあるform.htmlファイルでフォーム自体を記述します。 私の場合、フォームは次のようになります

  1. < form method = 'post' action = '{PARAMS.0}' > <!-- PARAMS.0 --> < input type = 'text' name = 'author' / > < input type = 'text' name = 'comment' / > < input type = 'submit' / > < / form >



  2. < form method = 'post' action = '{PARAMS.0}' > <!-- PARAMS.0 --> < input type = 'text' name = 'author' / > < input type = 'text' name = 'comment' / > < input type = 'submit' / > < / form >



  3. < form method = 'post' action = '{PARAMS.0}' > <!-- PARAMS.0 --> < input type = 'text' name = 'author' / > < input type = 'text' name = 'comment' / > < input type = 'submit' / > < / form >



  4. < form method = 'post' action = '{PARAMS.0}' > <!-- PARAMS.0 --> < input type = 'text' name = 'author' / > < input type = 'text' name = 'comment' / > < input type = 'submit' / > < / form >



  5. < form method = 'post' action = '{PARAMS.0}' > <!-- PARAMS.0 --> < input type = 'text' name = 'author' / > < input type = 'text' name = 'comment' / > < input type = 'submit' / > < / form >





次に、既存のマスターページテンプレート内にこのフォームをダウンロードして、すべてのコメントの下にフォームを表示する必要があります。 これを行うには、テンプレートtemplate.html内でテンプレートタグ<F3:include href = "form.html" />を使用します。 form.htmlファイルはtemplate.htmlと同じディレクトリにある必要があることを思い出させてください



ここで質問があります-送信されたデータを処理する方法は? すべてがシンプルです。 index.phpファイルで、メインページのPOSTメソッドのハンドラーを宣言します。

  1. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  2. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  3. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  4. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  5. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  6. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  7. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  8. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  9. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  10. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  11. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  12. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  13. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  14. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  15. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  16. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  17. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  18. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  19. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  20. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  21. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  22. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  23. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  24. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>



  25. require_once ( 'F3/F3.php' ) ; F3 :: set ( 'AUTOLOAD' , 'autoload/' ) ; F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite:guestbook.sqlite' ) ) ; F3 :: route ( 'GET /' , 'home' ) ; function home ( ) { $comments = new Axon ( 'comments' ) ; $all_comments = $comments -> find ( ) ; F3 :: set ( 'comments' , $all_comments ) ; F3 :: serve ( 'template.html' ) ; } F3 :: route ( 'POST /' , 'savecomment' ) ; function savecomment ( ) { $comments = new Axon ( 'comment' ) ; $comments -> copyFrom ( 'REQUEST' ) ; /* , . copyFrom $_REQUEST */ /* ... * */ $comments -> save ( ) ; // $F3 :: reroute ( '/' ) ; // } ?>





まあ、それだけです。 最低限のゲストブックの準備ができました。 約30行のコードが必要でした!



フレームワークサイト

Fat-Freeの最新バージョンをダウンロード

サポート

irc.freenode.netのIRCチャネル:#fatfree

フレームワークの作成者はBong Coscaです。 こちらが彼のブログです。



All Articles