PHP code example of bcosca / fatfree

1. Go to this page and download the library: Download bcosca/fatfree library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bcosca / fatfree example snippets

 php
$f3 = e('GET /',
    function() {
        echo 'Hello, world!';
    }
);
$f3->run();
 php
 = \Base::instance();
$f3->route('GET /',
    function() {
        echo 'Hello, world!';
    }
);
$f3->run();
 php
$f3->route('GET /about',
    function() {
        echo 'Donations go to a local charity... us!';
    }
);
 php
class WebPage {
    function display() {
        echo 'I cannot object to an object';
    }
}

$f3->route('GET /about','WebPage->display');
 php
$f3->route('GET /login','Auth::login');
 php
$f3->route('GET /brew/@count',
    function($f3) {
        echo $f3->get('PARAMS.count').' bottles of beer on the wall.';
    }
);
 php
$f3->route('GET /brew/@count',
    function($f3,$params) {
        echo $params['count'].' bottles of beer on the wall.';
    }
);
 php
$f3->route('GET /brew/*',
    function() {
        echo 'Enough beer! We always end up here.';
    }
);
 php
$f3->route('GET @beer_list: /beer', 'Beer->list');
 php
$f3->route('GET @beer_list: /beer/@country', 'Beer->bycountry');
$f3->route('GET @beer_list: /beer/@country/@village', 'Beer->byvillage');

// a set of key-value pairs is passed as argument to named route
$f3->reroute('@beer_list(@country=Germany)');

// if more than one token needed
$f3->reroute('@beer_list(@country=Germany,@village=Rhine)');
 nginx
server {
    root /var/www/html;
    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        fastcgi_pass ip_address:port;
        

$HTTP["host"] =~ "www\.example\.com$" {
    url.rewrite-once = ( "^/(.*?)(\?.+)?$"=>"/index.php/$1?$2" )
    server.error-handler-404 = "/index.php"
}
 php
$f3->route('GET|HEAD /obsoletepage',
    function($f3) {
        $f3->reroute('/newpage');
    }
);
 php
$f3->error(404);
 php
class Item {
    function get() {}
    function post() {}
    function put() {}
    function delete() {}
}

$f3=
 php
$f3->set('AUTOLOAD','autoload/');
 php
$f3->set('AUTOLOAD','admin/autoload/; user/autoload/; default/');
 php
$f3->set('AUTOLOAD','autoload/');
$obj=new Gadgets\iPad;
 php
$f3->set('AUTOLOAD','main/;aux/');
 php
$f3->set('AUTOLOAD','classes/');
$f3->route('GET|POST /','Main\Home::show');
 php
$f3->route('GET|POST /','Main\Home->show');
 php
$f3->route('GET /','Main->home');
 php
$f3->route('GET /example [ajax]','Page->getFragment');
$f3->route('GET /example [sync]','Page->getFull');
 php
$f3->set('var',value); // or
$f3->var=value;

$f3->set('hello.world','good morning'); // translates to: 'hello' == array('world'=>'good morning')
$f3->{'hello.world'}='good morning'; // same as prior statement
 php
$f3->mset(
    [
        'foo'=>'bar',
        'baz'=>123
    ]
);
 php
echo $f3->get('var'); // or
echo $f3->var;
 php
$f3->clear('var'); // or
unset($f3->var);
 php
$f3->exists('var') //
isset($f3->var)
 php
$f3->set('colors',['red','blue','yellow']);
$f3->push('colors','green'); // works like PHP's array_push()
echo $f3->pop('colors'); // returns 'green'

$f3->unshift('colors','purple'); // similar to array_unshift()
echo $f3->shift('colors'); // returns 'purple'

$f3->set('grays',['light','dark']);
$result=$f3->merge('colors','grays'); // merges the two arrays
 php
$f3->set('ONERROR',
    function($f3) {
        // custom error handler code goes here
        // use this if you want to display errors in a
        // format consistent with your site's theme
        echo $f3->get('ERROR.status');
    }
);
 php
$f3->set('DEBUG',3);
 php
$f3->set('DEBUG',0);
 php
$f3->config('setup.cfg');
 html
<p>Hello,  echo $name; 
 html
<p>Hello, <?= $name 
 php
$f3=ute('GET /',
    function($f3) {
        $f3->set('name','world');
        $view=new View;
        echo $view->render('template.htm');
        // Previous two lines can be shortened to:-
        // echo View::instance()->render('template.htm');
    }
);
$f3->run();
 php
$f3=ute('GET /',
    function($f3) {
        $f3->set('name','world');
        $template=new Template;
        echo $template->render('template.htm');
        // Above lines can be written as:-
        // echo Template::instance()->render('template.htm');
    }
);
$f3->run();
 php
$f3->set('buddy',['Tom','Dick','Harry']);
 html
{{ 2*(@page-1) }}
{{ (int)765.29+1.2e3 }}
<option value="F" {{ @active?'selected="selected"':'' }}>Female</option>
{{ var_dump(@xyz) }}
<p>That is {{ preg_match('/Yes/i',@response)?'correct':'wrong' }}!</p>
{{ @obj->property }}
 php
$f3->set('func',
    function($a,$b) {
        return $a.', '.$b;
    }
);
 php
$f3->set('fruits',['apple','orange ',' banana']);
 php
$f3->set('div',
    [
        'coffee'=>['arabica','barako','liberica','kopiluwak'],
        'tea'=>['darjeeling','pekoe','samovar']
    ]
);
 php
$f3->set('ENCODING','ISO-8859-1');
 php
echo Template::instance()->render('template.xml','application/xml');
 php
$f3->set('from','<[email protected]>');
$f3->set('to','<[email protected]>');
$f3->set('subject','Welcome');
ini_set('sendmail_from',$f3->get('from'));
mail(
    $f3->get('to'),
    $f3->get('subject'),
    Template::instance()->render('email.txt','text/html')
);
 php

return [
    'love'=>'I love F3',
    'today'=>'Today is {0,date}',
    'pi'=>'{0,number}',
    'money'=>'Amount remaining: {0,number,currency}'
];
 php

return [
    'love'=>'Ich liebe F3',
    'today'=>'Heute ist {0,date}',
    'money'=>'Restbetrag: {0,number,currency}'
];
 php
 $f3=Base::instance(); 
 php
$f3->set('LOCALES','dict/');
 php
$f3->set('LANGUAGE','de');
 php
$f3->set('ESCAPE',FALSE);
 php
 echo View::instance()->raw($html_content); 
 php
$db=new DB\SQL('sqlite:/absolute/path/to/your/database.sqlite');