I am trying to use afterFind to manipulate fields before displaying. It was working fine when I was using find('all') - then I switched to paginate() in order to, um, 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:
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'); $this->set('events', $sorted); }
So what changed from find('all') to paginate?
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'));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.