Skip to content

Larium/larium_model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abstract superclass for domain models.

Installation

You can install this library using Composer

Command line

In root directory of your project run through a console:

$ composer require "larium/model":"~1.0"

Composer.json

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';

Usage

<?php
# UserModel.php

class UserModel extends Larium\AbstractModel
{
    protected $username;

    protected $email;
}

Using default constructor.

$user = new UserModel();

$user->setUsername('JohnDoe');

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

Using create method

<?php

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

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

Using assignData method

<?php

$user = new UserModel();

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

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

Using create method with constructor arguments

<?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.

About

Abstract superclass for domain models

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages