General

  eZ Systems Website
  Technical documentation
  Editor documentation

This Documentation contains:
 
Technical documentation:



⚠ WARNING ! This documentation is deprecated !

Please go to the current Technical Documentation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt
Note
titleVersion compatibility

This recipe is compatible with eZ Publish 5.2 / 2013.09

 

Table of Contents

Status
colourYellow
titleEZP 5.2 / 2013.09

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 Platform can be used for multisite development, and as such the root location can vary.

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

...

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

...

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 );

        // ...
    }
}