Excerpt |
---|
Note |
---|
title | Version compatibility |
---|
| This recipe is compatible with eZ Publish 5.2 / 2013.09 |
|
Status |
---|
colour | Yellow |
---|
title | EZP 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 |
---|
language | php |
---|
title | eZ 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 |
---|
language | php |
---|
title | Before 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 );
// ...
}
} |