phpolar/model
最新稳定版本:2.2.1
Composer 安装命令:
composer require phpolar/model
包简介
Provides support for configuring the properties of an object for validation, formatting, and storage.
README 文档
README
PHPolar Model
Provides support for configuring the properties of an object for validation, formatting, and storage
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 |
统计信息
- 总下载量: 928
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-13