Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   eZ Publish 4.x / legacy

 
eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Note
titleVersion compatibility

This recipe is compatible with eZ Publish 5.2 / 2013.09

Table of Contents

Description

Knowledge of the root location is important since it can be a starting point for API queries, or even links to home page, but as eZ Publish can be used for multisite development, and as such root location can vary.

By default, root location ID is 2, but as it can be easily be changed by configuration, the best practice is to retrieve it dynamically.

Retrieving root location ID

Root location ID can be retrieved easily from ConfigResolver. Parameter name is content.tree_root.location_id.

Code Block
languagephp
titleIn a controller
<?php
namespace Acme\TestBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;


class DefaultController extends Controller
{
    public function fooAction()
    {
        // ...
 
        $rootLocationId = $this->getConfigResolver()->getParameter( 'content.tree_root.location_id' );
 
        // ...
    }
}

Retrieving the root location

From a template

Root location is exposed in the global Twig helper.

Code Block
languagehtml/xml
titleMaking a link to homepage
<a href="{{ path( ezpublish.rootLocation ) }}" title="Link to homepage">Home page</a>

From a controller

Code Block
languagephp
titleeZ Publish 5.2+ / 2013.11+
<?php
namespace Acme\TestBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;

class DefaultController extends Controller
{
    public function fooAction()
    {
        // ...

        $rootLocation = $this->getRootLocation();

        // ...
    }
}
Code Block
languagephp
titleBefore 5.2 / 2013.11
<?php
namespace Acme\TestBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;

class DefaultController extends Controller
{
    public function fooAction()
    {
        // ...

        $rootLocationId = $this->getConfigResolver()->getParameter( 'content.tree_root.location_id' );
        $rootLocation = $this->getRepository()->getLocationService()->loadLocation( $rootLocationId );

        // ...
    }
}