codeigniter4 / codeigniter4/CodeIgniter4
`Model::paginate()` behavior when `$page` exceeds the last page
- Ngôn ngữ chính
- PHP
- Star
- 6k
- Fork
- 2k
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 73
Mô tả
### PHP Version
8.3
### CodeIgniter4 Version
4.1.5
### CodeIgniter4 Installation Method
Manual (zip or tar.gz)
### Which operating systems have you tested for this bug?
Linux
### Which server did you use?
apache
### Database
MySQL 5.6
### What happened?
When i paginate the model like this `$UsersMode->orderBy('id_user', 'ASC')->paginate(8, 'group', $page_number);`
returns "`SELECT * FROM users ORDER BY id_user ASC LIMIT 8, 8`" based on offset and per page number
But my total count rows in the table are 24, so when i reach the end `16, 8` it returns me the same query as the last existing page in my database even with `$page_number = 100`
### Steps to Reproduce
```php
public function load_more($page_number = 2)
{
$UsersModel = new UsersModel();
$this->ViewData['Page'] = $page_number;
$this->ViewData['Users'] = $UsersMode->orderBy('id_user', 'ASC')->paginate(8, 'group', $page_number);
echo $UsersModel->db->getLastQuery();
}
```
returns "`SELECT * FROM users ORDER BY id_user ASC LIMIT 8, 8`"
But my total count rows in the table are 24, so when i reach the end `16, 8` `$page_number = 10` and go to a page number more than 3 it returns the same query "`SELECT * FROM users ORDER BY id_user ASC LIMIT 16, 8`"
### Expected Output
Going to a page number more than the total count rows of my table it should return the propper offset even if i have the total rows less than the per page number or less than the total count
`$page_number = 10` it should returns the query "`SELECT * FROM users ORDER BY id_user ASC LIMIT 80, 8`" even if i don't have enough records in my database table
### Anything else?
_No response_
Hướng dẫn đóng góp
Hướng nghiên cứu
Start at the Model::paginate() entry point and reproduce the behavior with the provided load_more() example, using 24 rows and page 10. Check whether the generated query preserves the requested offset; done means page 10 produces LIMIT 80, 8 even when no records exist there.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- mysql, php
- Lĩnh vực
- backend, database
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100