[英]Going from find('all') to paginate() breaks data in CakePHP?
I am trying to use afterFind to manipulate fields before displaying. 我正在尝试使用afterFind在显示之前操纵字段。 It was working fine when I was using find('all') - then I switched to paginate() in order to, um, paginate.
当我使用find('all')时,它工作得很好-然后我切换到paginate()以便进行分页。 And now it's telling me the following error:
现在,它告诉我以下错误:
Notice (8): Undefined index: Event [APP/Model/Event.php, line 24]
Notice (8): Undefined index: Event [APP/Model/Event.php, line 25]
The afterFind script: afterFind脚本:
public function afterFind($results, $primary = false) {
foreach ($results as $key => $val) {
if (isset($val['Event']['begindate'])) {
$results[$key]['Event']['begindate'] = $this->dateFormatAfterFind(
$val['Event']['begindate']
);
}
}
return $results;
}
This is the controller: 这是控制器:
public function index() {
$this->Event->recursive = 2;
$events = $this->Paginate('Event');
$sorted = Set::sort($events, '{n}.Event.begindate', 'asc'); $ sorted = Set :: sort($ events,'{n} .Event.begindate','asc'); $this->set('events', $sorted);
$ this-> set('events',$ sorted); }
}
So what changed from find('all') to paginate? 那么,从find('all')到分页又发生了什么?
You should try this code, may work for you 您应该尝试此代码,可能对您有用
public function index() {
$this->Event->recursive = 2;
$events = $this->Paginator->paginate('Event');
$this->set(compact('events'));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.