This repository was archived by the owner on Oct 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Model
Bastien Crettenand edited this page Mar 23, 2019
·
10 revisions
- An already structured database must exist
- The SLSQL script must be imported
Example 1:
class Users extends Model
{
public $name, $psw, $email, $id;
}
Example 2:
class Users extends Model
{
public $name, $psw, $email, $id;
public function __construct($name, $password, $mail = "test", $id = null)
{
$this->id = $id;
$this->name = $name;
$this->psw = $password;
$this->email = $mail;
}
}
Example 1:
$user = new Users();
$user->name = "CreBast";
$user->psw = "123";
$user->email = "[email protected]";
$user->Save();
Example 2:
$user = Users::get()->firstOrDefault()
Save object on database :
$user = new Users();
$user->name = "Bastien"; // Actually not on DB
$user->Save(); // Now yes
Get list of 'Users' with condition :
$user = Users::get('id = ? or id = ?', array(1, 2));
// Return ListModels() with users with ids 1 and 2 (if exist)
Remove object on database :
$user = Users::get('id = ?', array(1))->first();
$user->remove()
// Remove user with id 1
Return all ids on one list :
$user_ids = Users::ids();
// Return : array(1, 2, 3, ...)
Return all values of field on list :
$all_names = Users::all("name");
// Return : array(Bastien, José, Bastien, ...)
Return all values of field on list (distinct) :
$all_names = Users::all("name");
// Return : array(Bastien, José, ...)
Count number of objects :
$number = Users::count();
// Return : number
Count with condition :
$number = Users::countWhere('name = ?', array('Bastien');
// Return : number
Add new elements on ListModels() :
$listModels = new ListModels;
$listModels->add(new Users);
Return one list with all datas :
$users = Users::get()->all();
// Return all users
Return the first user returned. With default value if nothing :
$user = Users::get()->firstOrDefault(false);
// Return the first user returned. If nothing : false
Return the first user returned :
$user = Users::get()->first();
// Return the first user returned. If nothing : null
Return the last user returned. With default value if nothing :
$user = Users::get()->lastOrDefault(false);
// Return the last user returned. If nothing : false
Return the last user returned :
$user = Users::get()->last();
// Return the last user returned. If nothing : null
Feel free to correct the documentation 🙏