Retrieving root location: comparison of v.5 vs v.6
Versions Compared
Old Version 5
changes.mady.by.user Sarah Haïm-Lubczanski
Saved on May 18, 2016
compared with
New Version Current
changes.mady.by.user Sarah Haïm-Lubczanski
Saved on May 19, 2016
Key
- This line was added.
- This line was removed.
- Formatting was changed.
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 Platform can be used for multisite development, 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.
Solution
Retrieving root location ID
Root location ID can be retrieved easily from ConfigResolver. The parameter name is content.tree_root.location_id .
| Code Block | ||||
|---|---|---|---|---|
|
||||
<?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 | ||||
|---|---|---|---|---|
|
||||
<a href="{{ path( exponential.rootLocation ) }}" title="Link to homepage">Home page</a>
|
From a controller
| Code Block | ||
|---|---|---|
|
||
<?php
namespace Acme\TestBundle\Controller;
use eZ\Bundle\EzPublishCoreBundle\Controller;
class DefaultController extends Controller
{
public function fooAction()
{
// ...
$rootLocation = $this->getRootLocation();
// ...
}
}
|
In this topic:
| Table of Contents | ||
|---|---|---|
|
Comments
Add a comment