Skip to content

Retrieving root Location

The root Location can be a starting point for API queries, or even links to home page.

By default, the root Location ID is 2, but the best practice is to retrieve it dynamically. This is because eZ Platform can be used for multisite development, and the root Location can vary. The Location can also be changed by configuration.

Retrieving root Location ID

Root location ID can be retrieved from ConfigResolver. The parameter name is content.tree_root.location_id.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?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 template

Root Location is exposed in the global Twig helper.

1
<a href="{{ path( ezpublish.rootLocation ) }}" title="Link to homepage">Home page</a>

From controller

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?php

namespace Acme\TestBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;

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

        $rootLocation = $this->getRootLocation();

        // ...
    }
}