Skip to content

Commit 37da0d8

Browse files
committed
added delete function
1 parent ffebb7b commit 37da0d8

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/Core/Model.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Core;
33
use \Core\TwigCore;
44
use \Core\DoctrineCore;
5-
use \Core;
65
use \Core\Pagination;
76
class Model
87
{
@@ -151,8 +150,11 @@ public function first()
151150
$query = "select * from {$table} ".$this->generateWhere()." limit 1";
152151

153152
$row = $wpdb->get_row($query, ARRAY_A);
154-
155-
return new $class($row);
153+
if(is_array($row)) {
154+
return new $class($row);
155+
}else {
156+
return null;
157+
}
156158
}
157159

158160

@@ -252,6 +254,19 @@ public function save()
252254
return $this;
253255
}
254256

257+
public function destroy()
258+
{
259+
global $wpdb;
260+
261+
$table = self::getTableName();
262+
$data = $this->attributes;
263+
264+
$wpdb->delete($table, array('id'=>$data->id));
265+
unset($this->attributes, 'id');
266+
267+
return $this;
268+
}
269+
255270

256271

257272

src/Core/Pagination.php

100644100755
File mode changed.

src/Core/Session.php

100644100755
File mode changed.

src/Core/Validator.php

100644100755
File mode changed.

0 commit comments

Comments
 (0)