-
Notifications
You must be signed in to change notification settings - Fork 10
Model
Stefano Azzolini edited this page Jul 15, 2016
·
3 revisions
The Model class allow you to map database table to an object entity.
class User extends Model {
// Define the target database table and primary key,
// 'id' is the default.
const _PRIMARY_KEY_ = "users.id"
public $id,
$email,
$name;
}
$users = User::all();
The all
method accept pagination arguments
// Return page 2 with limit 20
$users = User::all(2, 20);
The where
method specifies the WHERE fragment of a SQL query.
// Return all users with gmail's email
$users = User::where("email LIKE '%@gmail.com'");
A new model can be created via the ModelName::create
factory method.
$mario = User::create([
"name" => "Mario",
"email" => "[email protected]"
]);
The resulting object implements an ActiveRecord pattern for accessing/modifying the model properties.
$mario->name = "Mario De Mario";
$mario->save();
Core is maintained by using the Semantic Versioning Specification (SemVer).
Copyright 2014-2016 Caffeina srl under the MIT license.
http://caffeina.com