NodesController::view PHP Method

view() public method

View
public view ( integer $id = null ) : void
$id integer
return void
    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']));
    }

Usage Example

Exemplo n.º 1
0
 /**
  * view function.
  * Called by the <username>/<slug>/<revision> route to show a preview page of
  * a particular node and revision combination.
  *
  * @access public
  * @param mixed $id. Id of the node to view(default: null)
  * @return void
  */
 public function view($id = null)
 {
     if (isset($this->params['slug'])) {
         $this->params['named']['slug'] = $this->params['slug'];
         $this->params['named']['revision'] = $this->params['revision'];
         $this->params['named']['type'] = $this->params['type'];
         // What node are we looking at?
         $nodeb = $this->Node->find('first', array('conditions' => array('Node.slug' => $this->params['slug'])));
         // Find the revision
         if ($nodeb) {
             $revision = $this->Revision->find('first', array('conditions' => array('Revision.node_id' => $nodeb['Node']['id'], 'or' => array('Revision.tag' => $this->params['revision'], 'Revision.id' => $this->params['revision']))));
         }
         $this->set('revision', $revision);
     }
     return parent::view($id);
 }