查看文档后,此代码可以运行:
$customers = Customers::find();
$numberPage = $this->request->getQuery("page", "int");
$paginator = new Paginator(array(
"data" => $customers,
"limit" => 10,
"page" => $numberPage
));
但是这个不起作用,我真的不明白为什么
$customers = Customers::find()->filter(
function ($customer) {
// Return only customers with a valid e-mail
if (filter_var($customer->email, FILTER_VALIDATE_EMAIL)) {
return $customer;
}
}
);
$numberPage = $this->request->getQuery("page", "int");
$paginator = new Paginator(array(
"data" => $customers,
"limit" => 10,
"page" => $numberPage
));
然后,我收到“内部错误”。奇怪的是,$ customers对象似乎有所改变。
有什么想法吗?
提前,谢谢。
答案 0 :(得分:2)
Model::find()
的结果应该是Phalcon\Mvc\Model\Resultset
Phalcon\Paginator\Adapter\Model
的分页符接受的Phalcon\Paginator\Adapter\NativeArray
个实例。
Resultset::filter()
方法的结果是一个模型实例数组,它不是Resultset的一个实例。要对数组进行分页,可以实现@NamedNativeQueries({
@NamedNativeQuery(name = "Users.byId", query = "Select * from users where userId=?", resultClass = Users.class),
@NamedNativeQuery(name = "Users.all", query = "Select * from users ", resultClass = Users.class),
@NamedNativeQuery(name = "Users.IdPass", query = "Select * from users where userName=? and password=? ", resultClass = Users.class) })
paginator。