public function view($id = null)
{
$Node = $this->{$this->modelClass};
if (isset($this->request->params['named']['slug']) && isset($this->request->params['named']['type'])) {
$Node->type = $this->request->params['named']['type'];
$type = $Node->Taxonomy->Vocabulary->Type->find('first', array('conditions' => array('Type.alias' => $Node->type), 'cache' => array('name' => 'type_' . $Node->type, 'config' => 'nodes_view')));
$node = $Node->find('viewBySlug', array('slug' => $this->request->params['named']['slug'], 'type' => $this->request->params['named']['type'], 'roleId' => $this->Croogo->roleId()));
} elseif ($id == null) {
$this->Session->setFlash(__d('croogo', 'Invalid content'), 'flash', array('class' => 'error'));
return $this->redirect('/');
} else {
$node = $Node->find('viewById', array('id' => $id, 'roleId' => $this->Croogo->roleId));
$Node->type = $node[$Node->alias]['type'];
$type = $Node->Taxonomy->Vocabulary->Type->find('first', array('conditions' => array('Type.alias' => $Node->type), 'cache' => array('name' => 'type_' . $Node->type, 'config' => 'nodes_view')));
}
if (!isset($node[$Node->alias][$Node->primaryKey])) {
$this->Session->setFlash(__d('croogo', 'Invalid content'), 'flash', array('class' => 'error'));
return $this->redirect('/');
}
$data = $node;
$event = new CakeEvent('Controller.Nodes.view', $this, compact('data'));
$this->getEventManager()->dispatch($event);
$this->set('title_for_layout', $node[$Node->alias]['title']);
$this->set(compact('node', 'type', 'comments'));
$this->Croogo->viewFallback(array('view_' . $type['Type']['alias'] . '_' . $node[$Node->alias]['slug'], 'view_' . $node[$Node->alias][$Node->primaryKey], 'view_' . $type['Type']['alias']));
}