初始化
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace app\models;
|
||||
|
||||
use core\base\Model;
|
||||
|
||||
/**
|
||||
* 文档管理模型
|
||||
*/
|
||||
class Document extends Model
|
||||
{
|
||||
protected $table = 'document';
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->order(['id DESC'])->fetchAll();
|
||||
}
|
||||
|
||||
public function getById($id)
|
||||
{
|
||||
return $this->where(['id = :id'], [':id' => $id])->fetch();
|
||||
}
|
||||
|
||||
public function getByCategory($category)
|
||||
{
|
||||
return $this->where(['category = :cat'], [':cat' => $category])->order(['id DESC'])->fetchAll();
|
||||
}
|
||||
|
||||
public function getCount()
|
||||
{
|
||||
$sql = 'SELECT COUNT(*) AS cnt FROM ' . $this->getTable();
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
return (int)($row['cnt'] ?? 0);
|
||||
}
|
||||
|
||||
public function getCategories()
|
||||
{
|
||||
$sql = 'SELECT DISTINCT category FROM ' . $this->getTable() . " WHERE category != '' ORDER BY category";
|
||||
$stmt = $this->pdo->query($sql);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user