PHP code example of besimple / i18n-routing-bundle
1. Go to this page and download the library: Download besimple/i18n-routing-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
besimple / i18n-routing-bundle example snippets
//app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new BeSimple\I18nRoutingBundle\BeSimpleI18nRoutingBundle(),
);
}
use Symfony\Component\Routing\RouteCollection;
use BeSimple\I18nRoutingBundle\Routing\RouteGenerator\I18nRouteGenerator;
$generator = new I18nRouteGenerator();
$collection = new RouteCollection();
$collection->addCollection(
$generator->generateRoutes(
'homepage',
array('en' => '/welcome', 'fr' => '/bienvenue', 'de' => '/willkommen'),
new Route('', array(
'_controller' => 'MyWebsiteBundle:Frontend:index'
))
)
);
return $collection;
use BeSimple\I18nRoutingBundle\Routing\Annotation\I18nRoute;
class NoPrefixController
{
/**
* @I18nRoute({ "en": "/welcome", "fr": "/bienvenue", "de": "/willkommen" }, name="homepage")
*/
public function indexAction() { }
}
use BeSimple\I18nRoutingBundle\Routing\RouteGenerator\I18nRouteGenerator;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
$generator = new I18nRouteGenerator();
$collection = new RouteCollection();
$collection->add('hello', new Route('/hello/{name}', array(
'_controller' => 'HelloBundle:Hello:index',
)));
$collection->addCollection(
$generator->generateRoutes(
'homepage',
array('en' => '/welcome/{name}', 'fr' => '/bienvenue/{name}', 'de' => '/willkommen/{name}'),
new Route('', array(
'_controller' => 'MyWebsiteBundle:Frontend:index',
))
)
);
return $collection;
echo $view['router']->generate('homepage.en')
echo $view['router']->generate('homepage')
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.