1.6 KiB
1.6 KiB
Ulmus
Welcome to the official Ulmus documentation.
Quick start
Creating a simple user exemple entity:
/app/entity/user.php
<?php
namespace MyApp\Entity;
use Ulmus\Entity\Field\Datetime;
/**
* @Table('name' => "user")
*/
class User
{
use \Ulmus\EntityTrait;
#[Field\Id]
public int $id;
#[Field]
public string $fullname;
#[Field]
public ? string $email;
#[Field]
public bool $isAdmin = false;
#[Field\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:
$user = Entity\User::repository()->loadFromPk((int) $_GET['id']);
Or we could also, load another single entity using a specific field:
# 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:
$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 :
INSERT INTO `user` VALUES fullname = :fullname, birthday = :birthday;
Binded using:
'fullname' => "Johnny Does",
'birthday' => "1980-01-15",