Created
September 12, 2016 17:46
-
-
Save iamjonbradley/c6c5d63a760a8f9d3781d1fe314789fd to your computer and use it in GitHub Desktop.
example controller view action
This file contains 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
<?php | |
public function view($id = null) | |
{ | |
$article = $this->Articles->find('all', [ | |
'conditions' => ['Articles.id' => $id], | |
'contain' => ['Categories', 'Users'] | |
])->first(); | |
if (empty($article)) { | |
$article = $this->Articles->find('all', [ | |
'conditions' => ['Articles.slug' => $id] | |
])->first(); | |
} | |
if (empty($article)) { | |
$this->Flash->error(__('The article could not found. Please, try again.')); | |
return $this->redirect($this->referer()); | |
} | |
$this->set('article', $article); | |
$this->set('_serialize', ['article']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment