Forest header image

Symfony Finland
Random things on PHP, Symfony and web development

Generate link in PHP using eZ Platform API

In eZ Platform there are plenty of links to go around as you create locations and tree structures. In templates it is well documented how to generate links to locations, but in PHP this is not well documented.

Here is how to do it:


// Load the URL Alias Generator service from the container
$urlAliasGenerator = $this->get('ezpublish.urlalias_generator');

// Get path
$urlAliasGenerator->getPathPrefixByRootLocationId($hit->valueObject->id);

That's easy, nothing to it. You just need to know how to do it. There might be some issues with siteaccess paths with this method, though.


Written by Jani Tarvainen on Monday December 5, 2016
Permalink -

« Facebook sharing metadata for eZ Platform with Open Graph Bundle - Using a eZ Platform / eZ Publish 5.4 for local development without images »