【发布时间】:2017-08-30 13:57:43
【问题描述】:
正如标题所说,我使用的是 Silex 和 Doctrine。不过,我想使用我自己的一些简单类来扩展 Doctrine。但我不知道在“扩展......?”之后该放什么。这是我如何扩展教义的示例:
public function action($action, $table, $where = array()) {
if(count($where) === 3) {
$operators = array('=', '>', '<', '>=', '<=');
$field = $where[0];
$operator = $where[1];
$value = $where[2];
if(in_array($operator, $operators)) {
$sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";
if(!$this->query($sql, array($value))->error()) {
return $this;
}
}
}
return false;
}
还有这个:
public function insert($table, $fields = array()) {
$keys = array_keys($fields);
$values = null;
$x = 1;
foreach($fields as $field) {
$values .= '?';
if ($x < count($fields)) {
$values .= ', ';
}
$x++;
}
$sql = "INSERT INTO {$table} (`" . implode('`, `', $keys) . "`) VALUES ({$values})";
if(!$this->query($sql, $fields)->error()) {
return true;
}
return false;
}
所以,创建一个扩展 Doctrine 的外部类。我的班级会是什么样子:
类 DB 扩展... {
//废话
}
【问题讨论】:
标签: php doctrine silex extends