PHPackages                             arousacode/webapp\_liblet - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. arousacode/webapp\_liblet

ActiveLibrary[Database &amp; ORM](/categories/database)

arousacode/webapp\_liblet
=========================

Small library to automatically load data from HTMl form in any PHP object, and to generate HTML inputs from it. Also load and store into PDO database.

v1.8(1y ago)014GPL-3.0-or-laterPHPPHP &gt;=8.1

Since Jun 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/arousacode/WebAppLiblet)[ Packagist](https://packagist.org/packages/arousacode/webapp_liblet)[ Docs](https://arousacode.github.io/WebAppLiblet/)[ RSS](/packages/arousacode-webapp-liblet/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (1)Dependencies (1)Versions (12)Used By (0)

WebAppLiblet
============

[](#webappliblet)

Small library to automatically :

- load data from HTMl form in any PHP object, and to generate HTML inputs from it.
- load and store data from/to the object using PDO database.

In orther to be able to manage HTMl form data in a PHP object, and to store it in a PDFO database:

PHP example
-----------

[](#php-example)

```
require_once('../../vendor/autoload.php');

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 " DEBUG: RECEIVED userData :\n-------------\n";
    print_r($userData);
    echo "";
}*/
?>
