PHP code example of arousacode / webapp_liblet

1. Go to this page and download the library: Download arousacode/webapp_liblet 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/ */

    

arousacode / webapp_liblet example snippets




use ArousaCode\WebApp\Types\Date;
use ArousaCode\WebApp\Types\Time;
use ArousaCode\WebApp\Types\DateTime;
use ArousaCode\WebApp\Types\TextArea;
use ArousaCode\WebApp\Types\Hidden;

class Operation
{
    use \ArousaCode\WebApp\Html\Form;

    #[Hidden]
    public ?string $operation='SAVE';
    #[Hidden]
    public ?string $mode=null;
}

class UserData
{

    use \ArousaCode\WebApp\Html\Form;
    use \ArousaCode\WebApp\Pdo\PDOExtended;

    public ?int $id;
    public string $sureName;
    public int $age;
    public float $height;
    #[DateTime]
    public \DateTime $dateOfBirth;
    #[Time]
    public \DateTime $exitTime;
    #[Date]
    public \DateTime $birthDay;
    #[TextArea]
    public string $description;
    public bool $chief;
    public ?bool $question;
}

$operation = new Operation();
$operation->loadData(INPUT_POST);

$userData = new UserData();
$userData->initDb(new \PDO("pgsql:dbname=webapp;host=webapp-postgresql","webapp","webapp"));

switch ($operation->operation) {
    case 'SAVE':
        $userData->loadData(INPUT_POST);
        $userData->upsert();
        break;
    case 'DELETE':
        $userData->loadData(INPUT_POST);
        $userData->delete();
        break;
    case 'COPY':
        $userData->id = null;
        break;
    default:
        //No operation requested: We expecto to get an ID passed by GET
        $userData->id = filter_input(INPUT_GET, 'id');
        break;
}

if($userData->id != null){
    //If there is an ID, we load the data from database. ALso if we have just stored it.
    $userData->load();
}

/*
if (isset($_POST['save'])) {
    echo "<pre> DEBUG: RECEIVED userData :\n-------------\n";
    print_r($userData);
    echo "</pre>";
}*/