📜 ⬆️ ⬇️

F3: a small PHP framework with great features



I want to bring to your attention a lightweight PHP-framework, which I recently stumbled upon and who immediately fell in love.

Fat-Free is somewhat similar to the famous Ruby framework Sinatra. The author of Fat-Free is obsessed with minimalism and cleanliness of the code, which positively affected this simple framework for developing a wide variety of applications.
')
Fat-Free consists of a single file and weighs only 55KB. In this case, the framework has the following functionality: a specific and quite convenient template engine, flexible caching, automatic spam protection, integrated tools for unit tests, a profiler code.

It is so small and fast that it can even be used to control Web server traffic.

It is also the only framework that protects your application from hotlinking and DoS attacks.


It doesn't matter if you are a beginner or a professional PHP programmer, Fat-Free is easy to use and powerful at the same time. It does not require installation or a clear directory structure. This framework allows you to write applications in object-oriented and procedural styles. The philosophy of Fat-Free and its approach to the MVC-architecture strive for minimalism of structural components, avoiding complexity and a balance between the elegance of code, application performance and programmer productivity.

Fat-Free comes with plugins that will help extend the framework's capabilities:



Here is the file that displays the greeting on the main page:
  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 ( ) ;

Getting Started


Note: for the framework to work, it needs PHP version 5.3 or higher and also installed and configured mod_rewrite!

In order not to make this manual too cumbersome, I decided to avoid writing design and some obvious features for our simple guestbook application.

To start, create a database in any way convenient for you. Both SQLite / MySQL and MongoDB can act as databases. Since the application is indicative and simple, I choose SQLite.

In my guestbook database, there is only one table - Comments , which contains the id , author and comment fields.

Create an index.php file in the root of your application and rename the htaccess file to .htaccess (with a dot in front).

Next, include the main and only framework file in index.php and determine the path to the database:
  1. require_once ( 'F3 / F3.php' ) ; // connect the framework
  2. F3 :: set ( 'DB' , array ( 'dsn' => 'sqlite: guestbook.sqlite' ) ) ; / * Initialization of connection to the database.
  3. Note: if you have sqlite version = 2, the DSN should look like this:
  4. 'dsn' => 'sqlite2: guestbook.sqlite'
  5. * /

In the first example, where the Hello World message is displayed, you saw one of the ways of processing routes (paths). In fact, there are several of them and you are free to choose:

1. The handler function of the route - as in the first example. The second parameter of the F3 :: rote () method is the function that we describe in the same file, anywhere

2. Anonymous function in the second parameter of the F3 :: rote () method:
  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. Static class method in the same second parameter:
  1. require_once 'path / to / F3.php' ;
  2. class MyClass {
  3. public static function hello ( ) {
  4. echo 'Hello, world!' ;
  5. }
  6. }
  7. F3 :: route ( 'GET /' , 'MyClass :: hello' ) ;
  8. F3 :: run ( ) ;

4. The usual class method:
  1. require_once 'path / to / F3.php' ;
  2. class MyClass {
  3. public function hello ( ) {
  4. echo 'Hello, world!' ;
  5. }
  6. }
  7. $ test = new MyClass ;
  8. F3 :: route ( 'GET /' , array ( $ test , 'hello' ) ) ;
  9. F3 :: run ( ) ;

5. Finally, a handler can be a separate file located in an arbitrary directory with other similar files. The directory with the handler files must be declared at the beginning of the index.php file, after which you can call the route handler file:
  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!' ; ?>

We continue the development of the guest book. In the index.php file, add the path to the plug-in files - this is what we need to use the ORM called Axon, which comes with Fat-Free:
  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' ) ) ;

Add the processing of a request for the main page in one of the above ways I choose the first, as the most obvious.
  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 />' ; } }

Here you go. Displaying comments is already working. You can proceed to add. But first I want to talk a bit about the templates.

The template path is set by the same method as the others:
  1. F3 :: set ( 'GUI' , ' ' ) ;

You cannot transfer a variable to a specific template. Variables in Fat-Free are set for the entire application. This is done using the familiar static method:
  1. F3 :: set ( '' , '' ) ;

Now this variable is available everywhere. In HTML code and a string view, its value is called as {@ variable}, in PHP code as:
  1. F3 :: get ( 'variable' ) ;

To invoke the template, use the serve method:
  1. F3 :: serve ( 'template.html' ) ;

So my application now looks like:
  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>

In this example, you can see how the Fat-Free template engine works: the loop processes a variable that contains all the comments.

The next step is to add a comment form to the page. To do this, first describe the form itself in the form.html file located in the template folder. In my case, the form looks like this.
  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 >

Next, you need to download this form within the existing template of the main page in order to display the form under all comments. To do this, inside the template.html template, use the <F3 template tag: include href = "form.html" />. Recall that the form.html file must be in the same directory as template.html

Now you should have a question - how to process the sent data? It's simple. Declare a handler for the POST method of the main page in the index.php file:
  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 ( '/' ) ; // } ?>

Well that's all. Minimal guestbook is ready. It took about 30 lines of code!

Framework site
Download the latest version of Fat-Free
Support
IRC channel on irc.freenode.net: #fatfree
The framework author is called Bong Cosca. Here is his blog.

Source: https://habr.com/ru/post/103167/


All Articles