1. Go to this page and download the library: Download miladm/data-object 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/ */
miladm / data-object example snippets
use miladm\DataObject;
class User extends DataObject
{
public string $name;
public int $age;
public string $email;
public function validateEmail()
{
return $this->email == '[email protected]';
}
public function validateName()
{
return strlen($this->name) >= 4;
}
public function validate()
{
return $this->validateName() &&
$this->validateEmail();
}
}
class User extends DataObject
{
public object $profile;
public object $feed;
public function init()
{
$this->profile = new Profile();
$this->feed = Feed::class;
}
}
class User extends DataObject
{ .... }
$user = UserModel::get_by_id(12);
$u = new User($user);
class User extends DataObject
{ .... }
$u = new User();
$user = UserModel::get_by_id(12);
$u->injectData($user);
class User extends DataObject
{
private $model;
public function init()
{
$this->model = UserModel::class;
}
public function loadUser_byId(int $id)
{
$this->injectData($this->model::where(['id' => $id])->getOne());
}
}
$user = new User;
$user->loadUser_byId(12);
// code above used as alternative to code below
// $user = UserModel::get_by_id(12);
// $u = new User($user);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.