$this->table() now had parameter for auto-escaping #0

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@118 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
aterekhov
2010-02-28 22:09:51 +00:00
parent a8322c3831
commit ec16e890e8

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Класс модели данных * Класс модели данных
* *
@ -39,7 +40,7 @@ abstract class Model
*/ */
public function getInsertId() public function getInsertId()
{ {
return $this->db->getInsertId($this->table(), $this->key); return $this->db->getInsertId($this->table(false), $this->key);
} }
/** /**
@ -66,8 +67,7 @@ abstract class Model
*/ */
public function get($id) public function get($id)
{ {
$sql = 'SELECT * FROM ' . $this->identify($this->table()) $sql = 'SELECT * FROM ' . $this->table() . ' WHERE ' . $this->identify($this->key) . '=' . (int) $id;
. ' WHERE ' . $this->identify($this->key) . '=' . (int) $id;
return $this->db->query($sql)->fetch(); return $this->db->query($sql)->fetch();
} }
@ -94,7 +94,7 @@ abstract class Model
*/ */
public function insert($data) public function insert($data)
{ {
if (! $this->db->insert($this->table(), $data)) { if (!$this->db->insert($this->table(false), $data)) {
return false; return false;
} }
return $this->getInsertId(); return $this->getInsertId();
@ -107,7 +107,7 @@ abstract class Model
*/ */
public function update($data, $where) public function update($data, $where)
{ {
return $this->db->update($this->table(), $data, $where); return $this->db->update($this->table(false), $data, $where);
} }
/** /**
@ -119,17 +119,18 @@ abstract class Model
if (is_int($where)) { if (is_int($where)) {
$where = $this->identify($this->key) . '=' . (int) $where; $where = $this->identify($this->key) . '=' . (int) $where;
} }
return $this->db->delete($this->table(), $where); return $this->db->delete($this->table(false), $where);
} }
/** /**
* @param bool $autoescape
* @return string * @return string
*/ */
public function table() public function table($autoescape = true)
{ {
if (! $this->table) { if (!$this->table) {
$this->table = substr(strtolower(get_class($this)), 0, -5/*strlen('Model')*/); $this->table = substr(strtolower(get_class($this)), 0, -5/*strlen('Model')*/);
} }
return $this->table; return $identify ? $this->identify($this->table) : $this->table;
} }
} }