WIP on docs and added basic enums supports
This commit is contained in:
1 parent
497fe5547b
commit
b6752f4364
22 files changed
+367
-35
No files matched your search
@@ -0,0 +1,95 @@
|
||||
# Ulmus
|
||||
|
||||
Welcome to the official Ulmus documentation.
|
||||
|
||||
## Quick start
|
||||
|
||||
Creating a simple user entity:
|
||||
|
||||
*/app/entity/user.php*
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace MyApp\Entity;
|
||||
|
||||
use Ulmus\Entity\Field\Datetime;
|
||||
|
||||
/**
|
||||
* @Table('name' => "user")
|
||||
*/
|
||||
class User
|
||||
{
|
||||
use \Ulmus\EntityTrait;
|
||||
|
||||
/**
|
||||
* @Id
|
||||
*/
|
||||
public int $id;
|
||||
|
||||
/**
|
||||
* @Field
|
||||
*/
|
||||
public string $fullname;
|
||||
|
||||
/**
|
||||
* @Field
|
||||
*/
|
||||
public ? string $email;
|
||||
|
||||
/**
|
||||
* @Field('name' => 'is_admin')
|
||||
*/
|
||||
public bool $isAdmin = false;
|
||||
|
||||
/**
|
||||
* @DateTime
|
||||
*/
|
||||
public Datetime $birthday;
|
||||
}
|
||||
```
|
||||
|
||||
### Loading a user using a Primary Key
|
||||
|
||||
With this entity, we could quickly load a user using the `@Id` field using:
|
||||
|
||||
```php
|
||||
$user = Entity\User::repository()->loadFromPk((int) $_GET['id']);
|
||||
```
|
||||
|
||||
Or we could also, load another single entity using a specific field:
|
||||
|
||||
```php
|
||||
# fetch a single user
|
||||
$user = Entity\User::repository()->loadOneFromField((string) $_POST['email'], 'email');
|
||||
|
||||
# Fetch every admins
|
||||
$admin_list = Entity\User::repository()->loadFromField(true, 'isAdmin');
|
||||
```
|
||||
|
||||
Using the same entity class, we could create a new user and save it using:
|
||||
|
||||
```php
|
||||
$user = new Entity\User();
|
||||
$user->fullname = "Johnny Does";
|
||||
$user->birthday = "1980-01-15";
|
||||
|
||||
if ( Entity\User::repository()->save($user) ) {
|
||||
echo "User created successfully !";
|
||||
}
|
||||
else {
|
||||
echo "User could not be saved :\";
|
||||
}
|
||||
```
|
||||
|
||||
Which would result in the following query (from MySQL adapter) being generated and executed :
|
||||
|
||||
```SQL
|
||||
INSERT INTO `user` VALUES fullname = :fullname, birthday = :birthday;
|
||||
```
|
||||
|
||||
Binded using:
|
||||
|
||||
```PHP
|
||||
'fullname' => "Johnny Does",
|
||||
'birthday' => "1980-01-15",
|
||||
```
|
||||
Reference in new issue
Block a user