You can install this library using Composer
In root directory of your project run through a console:
$ composer require "larium/model":"~1.0"
Include require line in your composer.json
file
{
require: {
"larium/model": "~1.0"
}
}
and run from console in the root directory of your project:
$ composer update
After this you must require autoload file from composer.
<?php
require_once 'vendor/autoload.php';
<?php
# UserModel.php
class UserModel extends Larium\AbstractModel
{
protected $username;
protected $email;
}
$user = new UserModel();
$user->setUsername('JohnDoe');
echo $user->getUserName(); # echoes JohnDoe.
<?php
$data = array('username' => 'johnDoe');
$user = UserModel::create($data);
echo $user->getUserName(); # echoes JohnDoe.
<?php
$user = new UserModel();
$data = array('username' => 'JohnDoe');
$user->assignData($data);
echo $user->getUsername(); # echoes JohnDoe
<?php
# CommentModel.php
class CommentModel extends AbstractModel
{
protected $user;
protected $content;
public function __construct(UserModel $user)
{
$this->user = $user;
}
}
<?php
$user = new UserModel();
$date = array('content' => 'Lorem Ipsum');
$comment = CommentModel::create($data, array($user));
$comment->getUser(); # return UserModel instance.