Message-ID: <250084884.3548.1485853600430.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3547_669921301.1485853600425" ------=_Part_3547_669921301.1485853600425 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Version compatibility
This recipe is compatible with eZ Publish 5.2 = / 2013.09
EZP 5.2 / 2= 013.09
Knowledge of the root location is important since it can be a starting p= oint for API queries, or even links to home page, but as eZ Publish can be = used for multisite de= velopment, 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 dy=
namically.
Root location ID can be retrieved easily from ConfigResolver. Parameter name is content.tr=
ee_root.location_id
.
<?php namespace Acme\TestBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; class DefaultController extends Controller { public function fooAction() { // ... $rootLocationId =3D $this->getConfigResolver()->getParameter(= 'content.tree_root.location_id' ); // ... } }=20
Root location is exposed in the glo= bal Twig helper.
<a href=3D"{{ path( ezpublish.rootLocation ) }}" title=3D"L= ink to homepage">Home page</a>=20
<?php namespace Acme\TestBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; class DefaultController extends Controller { public function fooAction() { // ... $rootLocation =3D $this->getRootLocation(); // ... } }=20
<?php namespace Acme\TestBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; class DefaultController extends Controller { public function fooAction() { // ... $rootLocationId =3D $this->getConfigResolver()->getParameter(= 'content.tree_root.location_id' ); $rootLocation =3D $this->getRepository()->getLocationService(= )->loadLocation( $rootLocationId ); // ... } }=20