PHP code example of larium / model

1. Go to this page and download the library: Download larium/model 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/ */

    

larium / model example snippets





# UserModel.php

class UserModel extends Larium\AbstractModel
{
    protected $username;

    protected $email;
}

$user = new UserModel();

$user->setUsername('JohnDoe');

echo $user->getUserName(); # echoes JohnDoe.



$data = array('username' => 'johnDoe');
$user = UserModel::create($data);

echo $user->getUserName(); # echoes JohnDoe.



$user = new UserModel();

$data = array('username' => 'JohnDoe');
$user->assignData($data);

echo $user->getUsername(); # echoes JohnDoe



# CommentModel.php

class CommentModel extends AbstractModel
{
    protected $user;

    protected $content;

    public function __construct(UserModel $user)
    {
        $this->user = $user;    
    }
}


$user = new UserModel();
$date = array('content' => 'Lorem Ipsum');
$comment = CommentModel::create($data, array($user));

$comment->getUser(); # return UserModel instance.