Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

没有分页时pagination返回null,有分页,但是没有上一页时previous也需要返回null #1

Closed
haibin2017 opened this issue Oct 25, 2017 · 2 comments

Comments

@haibin2017
Copy link

haibin2017 commented Oct 25, 2017

当分页中没有上一页时,previous需要返回null;没有下一页时,next需要返回null.
这样可以保持dingo api接口的完整性,调用api返回数据时因为格式固定了,只需判断有没有值即可,方便使用;
建议改为:

if ($currentPage > 1) {
    $pagination['links']['previous'] = $paginator->getUrl($currentPage - 1);
} else {
    if ($lastPage > 1 && $currentPage == 1) {
        $pagination['links']['previous'] = null;
    }
}

if ($currentPage < $lastPage) {
    $pagination['links']['next'] = $paginator->getUrl($currentPage + 1);
} else {
    if ($lastPage > 1 && $currentPage == $lastPage) {
        $pagination['links']['next'] = null;
    }
}

如下图所示,当是第一页并且有多页时,previous应为null,这样返回的分页格式固定不变,变的是数据和值。
image

@liyu001989
Copy link
Owner

也就是 如果没有上一页,下一页,links为null,其他情况,links的previous,next始终存在。我再想一下

@haibin2017
Copy link
Author

嗯 �对的;好的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants