Skip to content

Instantly share code, notes, and snippets.

@iamjonbradley
Created September 12, 2016 17:46
Show Gist options
  • Save iamjonbradley/c6c5d63a760a8f9d3781d1fe314789fd to your computer and use it in GitHub Desktop.
Save iamjonbradley/c6c5d63a760a8f9d3781d1fe314789fd to your computer and use it in GitHub Desktop.
example controller view action
<?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