PHP code example of yasiekz / router-bundle

1. Go to this page and download the library: Download yasiekz/router-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/ */

    

yasiekz / router-bundle example snippets


$bundles = array(
                new Yasiekz\RouterBundle\YasiekzRouterBundle(),
            )

use Yasiekz\RouterBundle\Service\RoutableCmsInterface;

class YourClass implements RoutableCmsIterface
{
    public function getPossibleRoutes()
    {
        // method should return an array of aviable routes as below
        return array(
            'destination1' => 'routingName1',
            'destination2' => 'routingName2'
        );
    }

    public function getRouterParameters($routeName, $destination = null);
    {
        // method should return parameters that is necessary to create routing depend on $destination parameter:
        return array(
            'id' => $this->getId()
        );
    }
}

$object = new YourClass();
$url = $this->generateUrl($object, 'edit');

$object = new YourClass();
$paramers = array(); // here might be additional params which be marged to routing
$url = $this->generateUrl($object, $parameters);

use Yasiekz\RouterBundle\Service\RoutableMultiFrontInterface;

class YourClass implements RoutableMultiFrontInterface
{
    const DESTINATION_ARTICLE = 'article';

    public function getRouteName($parameters = array(), $destination = null)
    {
        // method should return routeName for given object and parameters or destination
        if ($destination == self::DESTINATION_ARTICLE) {
            return 'yourclass_detail';
        }
        return 'yourclass_default';
    }

    public function getRouterParameters($routeName, $destination = null);
    {
        // method should return parameters that is necessary to create routing depend on $routeName parameter:

        return array(
            'id' => $this->getId()
        );
    }
}

$object = new YourClass();
$parameters = array('destination' => 'article'); // here might be additional params which be marged to routing
$url = $this->generateUrl($object, $parameters);