1. Go to this page and download the library: Download wtframework/orm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wtframework / orm example snippets
use WTFramework\ORM\Model;
class User extends Model {}
class User extends Model
{
public const TABLE = 'x_users';
}
class User extends Model
{
public const PRIMARY_KEY = 'id';
}
class User extends Model
{
public const CONNECTION = 'mirror';
}
use WTFramework\ORM\Model;
use WTFramework\ORM\Relationships\BelongsTo;
use WTFramework\ORM\Relationships\Has;
use WTFramework\ORM\Relationships\HasMany;
use WTFramework\ORM\Relationships\HasManyThrough;
use WTFramework\ORM\Relationships\HasThrough;
class User extends Model
{
public function role(): BelongsTo
{
return $this->belongsTo(UserRole::class);
}
public function profile(): Has
{
return $this->has(Profile::class);
}
public function revisions(): HasMany
{
return $this->hasMany(UserRevision::class);
}
public function owner(): HasOneThrough
{
return $this->hasOneThrough(Owner::class, UserOwner::class);
}
public function permissions(): HasManyThrough
{
return $this->hasManyThrough(Permission::class, UserPermission::class);
}
}
class User extends Model
{
public const PRIMARY_KEY = 'id';
public function role(): BelongsTo
{
return $this->belongsTo(UserRole::class, local_key: 'role_id');
}
public function profile(): Has
{
return $this->has(Profile::class, foreign_key: 'user_id');
}
public function revisions(): HasMany
{
return $this->hasMany(UserRevision::class, foreign_key: 'user_id');
}
public function owner(): HasOneThrough
{
return $this->hasOneThrough(Owner::class, UserOwner::class, foreign_key: 'owner_id', pivot_local_key: 'user_id');
}
public function permissions(): HasManyThrough
{
return $this->hasManyThrough(Permission::class, UserPermission::class, foreign_key: 'permission_id', pivot_local_key: 'user_id');
}
}