Created
December 2, 2015 16:51
-
-
Save bdunogier/06e707fba0ba9f8bcb9a to your computer and use it in GitHub Desktop.
How to generate an absolute URI from a Location with eZ Platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @license For full copyright and license information view LICENSE file distributed with this source code. | |
*/ | |
namespace BD\SandboxBundle\Command; | |
use eZ\Publish\Core\MVC\Symfony\Routing\RouteReference; | |
use eZ\Publish\Core\MVC\Symfony\SiteAccess; | |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\RequestStack; | |
class SandboxCommand extends ContainerAwareCommand | |
{ | |
protected function configure() | |
{ | |
$this->setName('bd:sandbox'); | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$locationService = $this->getContainer()->get('ezpublish.api.service.location'); | |
$routeRefGenerator = $this->getContainer()->get('ezpublish.route_reference.generator'); | |
$requestStack = new RequestStack(); | |
$request = new Request(); | |
$requestStack->push($request); | |
$routeRefGenerator->setRequestStack($requestStack); | |
$this->getContainer()->get('ezpublish.siteaccess_router')->setSiteAccess(new SiteAccess('site')); | |
$router = $this->getContainer()->get('router'); | |
$routeReference = $routeRefGenerator->generate($locationService->loadLocation(54)); | |
$routeReference->set('siteaccess', 'other_site'); | |
$output->writeln("url: " . $router->generate($routeReference, [], 'true')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In a web context, this should be sufficient: