Files
juipphp/fastphp/base/Model.php

47 lines
1.0 KiB
PHP
Raw Normal View History

2020-10-03 17:23:32 +08:00
<?php
namespace fastphp\base;
use fastphp\db\Sql;
class Model extends Sql
{
protected $model;
public function __construct()
{
//获取数据库表名
if(!$this->table){
//获取模型类名称
$this->model = get_class($this);
//删除模型名最后的model
$this->model = substr($this->model,0,-5);
//数据库表名与类名一致
$this->table = strtolower($this->model);
}
}
2020-10-11 19:23:42 +08:00
/**
* 获取总数目
*
*/
public function getCount(){
return $this->field('count(1) as count')->fetch();
}
/**
* 按照页数获取数据
* @param $fields 'id,count(1)...'
* @param $order 'id desc'/'id asc'
* @param $limit = '100' 限制查询100条
* $limit = '2,100' 查询第二页 100条数据
*/
public function getListPage($fields = '*',$order = 'id desc', $page = '50')
{
return $this->field($fields)->order($order)->limit($page)->fetchAll();
}
2020-10-03 17:23:32 +08:00
}