微信截图_20171124095230.png
调试
News.php(Model)
public function getNewsByCondition($condition = [], $from, $size = 5)
{
if (!isset($condition['status'])) {
$condition['status'] = [
'neq', config('code.status_delete')
];
}
$order = ['id' => 'desc'];
$result = $this->where($condition)
->field($this->getListField())
->limit($from, $size)
->order($order)
->select();
//echo $this->getLastSql();exit();
return $result;
}
News.php(Controller)
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/23
* Time: 17:03
*/
namespace app\api\controller\v1;
use app\api\controller\Common;
class News extends Common
{
public function index()
{
//仿照之前讲解的validate验证机制 做相关检验
$data = input('get.');
$whereData['status'] = config('code.status_normal');
if(!empty($data['catid'])){
$whereData['catid'] = input('get.catid',0,'intval');
}
if (!empty($data['title'])) {
$whereData['title'] = ['like', '%' . $data['title'] . '%'];
}
$this->getPageAndSize($data);
$total = model('News')->getNewsByCountCondition($whereData);
$news = model('News')->getNewsByCondition($whereData, $this->from, $this->size);
$result = [
'total' => $total,
'page_num' => ceil($total / $this->size),
'list' => $this->getDealNews($news),
];
return show(1, 'OK', $result, 200);
}
}
if(!empty($data['catid']
){
$whereData['catid'] = input('get.catid',0,'intval');
}
if (!empty($data['title'])) {
$whereData['title'] = ['like', '%' . $data['title'] . '%'];
}
)
微信截图_20171124102209.png
网友评论