Skip to content
/ model Public

Provides support for configuring the properties of an object for validation, formatting, and storage.

License

Notifications You must be signed in to change notification settings

phpolar/model

Repository files navigation

phpolar logo

PHPolar Model

Provides support for configuring the properties of an object for validation, formatting, and storage

Coverage Status Latest Stable Version Total Downloads PHP Version Require

Example 1

<!DOCTYPE html>
<?php
namespace MyApp;

use Phpolar\Phpolar\FormControlTypes;

(function (PersonForm $view) {
?>
<html>
    <body style="text-align:center">
        <h1><?= $view->title ?></h1>
        <div class="container">
            <form action="<?= $view->action ?>" method="post">
                <?php foreach ($view as $propName => $propVal): ?>
                    <label><?= $view->getLabel($propName) ?></label>
                    <?php switch ($view->getFormControlType($propName)): ?>
                        <?php case FormControlTypes::Input: ?>
                            <input type="text" value="<?= $propVal ?>" />
                        <?php case FormControlTypes::Select: ?>
                            <select>
                                <?php foreach ($propVal as $name => $item): ?>
                                    <option value="<?= $item ?>"><?= $name ?></option>
                                <?php endforeach ?>
                            </select>
                    <?php endswitch ?>
                <?php endforeach ?>
            </form>
        </div>
    </body>
</html>
<?php
})($this);

Use Attributes to Configure Models

use Phpolar\Phpolar\AbstractModel;

class Person extends AbstractModel
{
    public string $title = "Person Form";

    public string $action = "somewhere";

    #[MaxLength(20)]
    public string $firstName;

    #[MaxLength(20)]
    public string $lastName;

    #[Column("Residential Address")]
    #[Label("Residential Address")]
    #[MaxLength(200)]
    public string $address1;

    #[Column("Business Address")]
    #[Label("Business Address")]
    #[MaxLength(200)]
    public string $address2;
}

Thresholds

Source Code Size Memory Usage
21 kB 175 kB

About

Provides support for configuring the properties of an object for validation, formatting, and storage.

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages