Change protected attrs to static protected.

This commit is contained in:
kj 2020-05-11 03:11:11 -04:00
parent 2ba6079f17
commit c9f6887d5b
1 changed files with 10 additions and 11 deletions

View File

@ -18,10 +18,9 @@ class ModelMySQL {
public $id; public $id;
protected $primaryKey = 'id'; static protected $primaryKey = 'id';
protected $ignoreSave = ['id']; static protected $ignoreSave = ['id'];
protected $forceSave = []; static protected $forceSave = [];
static protected $table; static protected $table;
static protected $tableSufix = 's'; static protected $tableSufix = 's';
static protected $db; static protected $db;
@ -185,11 +184,11 @@ class ModelMySQL {
$result[$att] = $this->$att; $result[$att] = $this->$att;
} }
foreach ($this->ignoreSave as $del) { foreach (static::$ignoreSave as $del) {
unset($result[$del]); unset($result[$del]);
} }
foreach ($this->forceSave as $value) { foreach (static::$forceSave as $value) {
$result[$value] = $this->$value; $result[$value] = $this->$value;
} }
@ -229,7 +228,7 @@ class ModelMySQL {
} }
$table = static::table(); $table = static::table();
$pk = $this->primaryKey; $pk = static::$primaryKey;
$pkv = $this->$pk; $pkv = $this->$pk;
$sql = "UPDATE $table SET ".join(', ', $set)." WHERE $pk='$pkv'"; $sql = "UPDATE $table SET ".join(', ', $set)." WHERE $pk='$pkv'";
static::query($sql); static::query($sql);
@ -252,7 +251,7 @@ class ModelMySQL {
$sql = "INSERT INTO $table (".join(', ', $into).") VALUES (".join(', ', $values).")"; $sql = "INSERT INTO $table (".join(', ', $into).") VALUES (".join(', ', $values).")";
static::query($sql); static::query($sql);
$pk = $this->primaryKey; $pk = static::$primaryKey;
$this->$pk = $db->insert_id; $this->$pk = $db->insert_id;
} }
@ -261,7 +260,7 @@ class ModelMySQL {
* llama a update para actualizar o add para insertar una nueva fila. * llama a update para actualizar o add para insertar una nueva fila.
*/ */
public function save() { public function save() {
$pk = $this->primaryKey; $pk = static::$primaryKey;
if (isset($this->$pk)) if (isset($this->$pk))
$this->update(); $this->update();
else else
@ -280,7 +279,7 @@ class ModelMySQL {
} }
$table = static::table(); $table = static::table();
$pk = $this->primaryKey; $pk = static::$primaryKey;
$pkv = $this->$pk; $pkv = $this->$pk;
$sql = "DELETE FROM $table WHERE $pk='$pkv'"; $sql = "DELETE FROM $table WHERE $pk='$pkv'";
static::query($sql); static::query($sql);
@ -622,7 +621,7 @@ class ModelMySQL {
* @return ModelMySQL * @return ModelMySQL
*/ */
public static function getById($id) { public static function getById($id) {
return static::where('id', $id)->getFirst(); return static::where(static::$primaryKey, $id)->getFirst();
} }
/* /*