Skip to content

Instantly share code, notes, and snippets.

@flangofas
Created March 9, 2016 10:49
Show Gist options
  • Save flangofas/1fa20dd654ae7d176581 to your computer and use it in GitHub Desktop.
Save flangofas/1fa20dd654ae7d176581 to your computer and use it in GitHub Desktop.
Cakephp 3 - isEmpty example
public function index($sliderId = null)
{
$exists = $this->Slides->Sliders->exists(['id' => $sliderId]);
if (!$exists) {
throw new RecordNotFoundException(__('Cannot find the provided slider'));
}
$this->paginate = [
'contain' => ['Sliders']
];
$query = $this->Slides
->find('all', [
'contain' => [
'SlideImages' => [
'sort' => [
'created' => 'DESC'
]
]
]
])
->where(['slider_id' => $sliderId]);
// if ($query->isEmpty()) {
// $this->Flash->set(__('No slides were found. Please add one.'));
// return $this->redirect(['action' => 'add', $sliderId]);
// }
$slides = $this->paginate($query);
$this->set(compact('slides'));
$this->set('_serialize', ['slides']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment