Feature/add e shop
This commit is contained in:
@@ -68,12 +68,17 @@ class TTCrudBaseModel {
|
||||
}
|
||||
|
||||
|
||||
public static function get($id): TTCrudBaseModel {
|
||||
public static function get($id, $die= false): TTCrudBaseModel {
|
||||
$FronkDB = FronkDB::singleton();
|
||||
$db = $FronkDB->link;
|
||||
$id = $db->real_escape_string($id);
|
||||
$table = self::getTable();
|
||||
$sql = "SELECT * FROM `$table` WHERE `id` = $id";
|
||||
|
||||
if($die) {
|
||||
die($sql);
|
||||
}
|
||||
|
||||
$result = $db->query($sql);
|
||||
// as TTCRudBaseModel is abstract, we need to get the class name of the child class
|
||||
$class = get_called_class();
|
||||
@@ -148,6 +153,13 @@ class TTCrudBaseModel {
|
||||
if ($field === "id") {
|
||||
continue;
|
||||
}
|
||||
// TODO: make this cleaner
|
||||
if ($value === "" && (new ReflectionProperty(get_called_class(), $field))->getType()->getName() === "float") {
|
||||
$value = null;
|
||||
}
|
||||
if ($value === "" && (new ReflectionProperty(get_called_class(), $field))->getType()->getName() === "int") {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
$values[] = $value === null ? "`$field` = NULL" : "`$field` = '" . $db->real_escape_string($value) . "'";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user