Created
March 9, 2016 10:49
-
-
Save flangofas/1fa20dd654ae7d176581 to your computer and use it in GitHub Desktop.
Cakephp 3 - isEmpty example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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