PHPackages                             asgard/entityform - 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. asgard/entityform

ActiveLibrary

asgard/entityform
=================

v0.3.1(10y ago)024MITPHPPHP &gt;=5.5.9

Since Sep 9Pushed 8y agoCompare

[ Source](https://github.com/asgardphp/entityform)[ Packagist](https://packagist.org/packages/asgard/entityform)[ RSS](/packages/asgard-entityform/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

\#EntityForm

[![Build Status](https://camo.githubusercontent.com/cac671ea023b460837b6ee8b31859fd6c5edad5686daf2d7d189a67b0dacc030/68747470733a2f2f7472617669732d63692e6f72672f6173676172647068702f656e74697479666f726d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/asgardphp/entityform)

Entityform help you generate forms from entities. It creates the form fields corresponding to all the entity properties. Entityform is a sub-class of [Form](docs/form).

- [Installation](#installation)
- [Usage in the Asgard Framework](#usage-asgard)
- [Usage outside the Asgard Framework](#usage-outside)
- [Add entity relations](#relations)
- [Save the entity](#save)
- [Get the entity](#get)
- [EntityFieldSolver](#solver)

\##Installation **If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries.**

```
composer require asgard/entityform 0.*

```

\##Usage in the Asgard Framework The advantage of using the form service is that it will provides the Form with all the necessary dependencies:

```
$request = \Asgard\Http\Request::CreateFromGlobals();
$entity  = new Article;
$container->make('entityForm', [
	$entity, #required
	[ #optional
		'action'  => 'form.php',
		'enctype' => 'multipart/form-data',
		'attrs'   => [
			'class' => 'formClass'
		]
	],
	$request, #optional, Asgard can provide the form with the current request
]);

```

The [container](docs/container) is often accessible as a method parameter or through a [ContainerAware](docs/container#containeraware) object. You can also use the [singleton](docs/container#usage-outside) but it is not recommended.

\##Usage outside the Asgard Framework Here you will have to provide the dependencies yourself (see the next section):

```
$entityFieldsSolver = new \Asgard\Entityform\EntityFieldsSolver;
$request            = \Asgard\Http\Request::CreateFromGlobals();
$entity             = new Article;
$form = new \Asgard\Entityform\Entityform(
	$entity, #required
	[ #optional
		'action'  => 'form.php',
		'enctype' => 'multipart/form-data',
		'attrs'   => [
			'class' => 'formClass'
		]
	],
	$request, #optional, if not request is provided the form will automatically use \Asgard\Http\Request::createFromGlobals()
	$entityFieldsSolver #optional, Asgard can automatically retrieve an instance of EntityFieldsSolver
);

```

\##Add entity relations

If the entity form was created from an entity having a "comments" relation, you embed it in the form with:

```
$form->addRelation('comments');

```

This will add a field for selecting comments related to the entity. Works for all kinds of relations, "one" and "many".

\##Save the entity

To save the entity, simple do:

```
$form->save();

```

If there is a validation error, it will throw the exception \\Asgard\\Form\\FormException. Refer to the [Form documentation](docs/form) to know how to handle exceptions and errors.

\##Get the entity

```
$form->getEntity();

```

\##EntityFieldSolver

In order to tell the entityform how to create fields from entity properties, you can use the Asgard\\Entityform\\EntityFieldsSolver class. By default it already handles Text, text, Double, Integer, Email, Boolean, Date, Datetime, File entity properties (all in Asgard\\Entity\\Property\\). If the EntityFieldsSolver does not know what type of field to create for a specific property, it will return a \\Asgard\\Form\\Field\\TextField field by default.

To extend the entityFieldsSolver add a callback which will return a form field object:

```
$cb = function(\Asgard\Entity\Property $property) {
	if(get_class($property) == 'Asgard\Entity\Property\DateProperty')
		return new MyOwnDateField;
};
$fieldsSolver->add($cb);

```

For entity properties with multiple values, use:

```
$cb = function(\Asgard\Entity\Property $property) {
	if(get_class($property) == 'Asgard\Entity\Property\DateProperty')
		return new \Asgard\Form\DynamicGroup;
};
$fieldsSolver->addMany($cb);

```

If the callback returns null it will be ignored.

You can also nest other solvers:

```
$anotherFieldsSolver->addSolver($fieldsSolver);

```

If $anotherFieldsSolver cannot solve the field, it will ask to the nested solvers.

To solve a field from an entity property:

```
$form->solve($Definition->getProperty('title'));

```

To get the EntityFieldSolver from a form:

```
$fieldsSolver = $form->getEntityFieldsSolver();

```

To set the EntityFieldsSolver for a form:

```
$form->addEntityFieldsSolver($cb);

```

\###Contributing

Please submit all issues and pull requests to the [asgardphp/asgard](http://github.com/asgardphp/asgard) repository.

### License

[](#license)

The Asgard framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~204 days

Total

4

Last Release

3657d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.4.0

v0.3.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/352850?v=4)[leyou](/maintainers/leyou)[@leyou](https://github.com/leyou)

---

Top Contributors

[![h0gar](https://avatars.githubusercontent.com/u/439138?v=4)](https://github.com/h0gar "h0gar (79 commits)")

### Embed Badge

![Health badge](/badges/asgard-entityform/health.svg)

```
[![Health](https://phpackages.com/badges/asgard-entityform/health.svg)](https://phpackages.com/packages/asgard-entityform)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
