PHPackages                             ongr/router-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. ongr/router-bundle

Abandoned → [ongr/router-bundle](/?search=ongr%2Frouter-bundle)Symfony-bundle[HTTP &amp; Networking](/categories/http)

ongr/router-bundle
==================

Bundle for ONGR routing.

v2.0.1(9y ago)639.9k132MITPHPPHP &gt;=5.6

Since Oct 30Pushed 9y ago16 watchersCompare

[ Source](https://github.com/ongr-io/RouterBundle)[ Packagist](https://packagist.org/packages/ongr/router-bundle)[ Docs](http://ongr.io)[ RSS](/packages/ongr-router-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (19)Used By (2)

ONGR Router Bundle
==================

[](#ongr-router-bundle)

Router Bundle allows to define and match URLs for elasticsearch documents. At url matching phase it additionaly searches for elasticsearch documents with specified url.

This can be used for generating/matching nice URLs for any document. Beautiful URLs help SEO and improve user's usability experience.

If you have any questions, don't hesitate to ask them on [![Join the chat at https://gitter.im/ongr-io/support](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/ongr-io/support)chat, or just come to say Hi ;).

[![Build Status](https://camo.githubusercontent.com/f4e94800177153c3d25df864524884740ba65638372c91925e55a5d838a8fb30/68747470733a2f2f7472617669732d63692e6f72672f6f6e67722d696f2f526f7574657242756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ongr-io/RouterBundle)[![Coverage Status](https://camo.githubusercontent.com/df0e0933294a3dd276cea0d903385769ba19ad0bbf7c575e0d3ad6a998d6a478/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6f6e67722d696f2f526f7574657242756e646c652f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/ongr-io/RouterBundle?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/f3c6ef76c5097eadc592f28103acec2277fcab6345002cab866944e9a2c79543/68747470733a2f2f706f7365722e707567782e6f72672f6f6e67722f726f757465722d62756e646c652f762f737461626c65)](https://packagist.org/packages/ongr/router-bundle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d646c92d8ca8da7f1cfadc2c6ea8d1478716497285369d7f8cbd4557f8ee6881/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6e67722d696f2f526f7574657242756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ongr-io/RouterBundle/?branch=master)

Documentation
-------------

[](#documentation)

The online documentation of the bundle is [here](Resources/doc/index.md)

For contribution rules take a look at [contribute](Resources/doc/contribute.md) topic.

Setup the bundle
----------------

[](#setup-the-bundle)

> This bundle strongly uses [ONGR Elasticsearch Bundle](https://github.com/ongr-io/ElasticsearchBundle). We assume that you are familiar with it and it already suits your needs.

#### Step 1: Install Router bundle

[](#step-1-install-router-bundle)

Router bundle is installed using [Composer](https://getcomposer.org).

```
composer require ongr/router-bundle "~1.0"
```

Enable Router and Elasticsearch bundles in your AppKernel:

```
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
        new ONGR\RouterBundle\ONGRRouterBundle(),
    ];
}
```

Yep, that's it, **1 step** installation. All the next steps are demonstration how to setup product document with SEO URLs. So look below how easy it is and adapt it for your needs.

#### Step 2: Add configuration

[](#step-2-add-configuration)

Add minimal configuration for Router and Elasticsearch bundles.

```
# app/config/config.yml

ongr_elasticsearch:
    analysis:
        analyzer:
            urlAnalyzer:
                type: custom
                tokenizer: keyword
                filter: [lowercase]
    connections:
        default:
            index_name: acme
    managers:
        default:
            connection: default
            mappings:
                - AppBundle

ongr_router:
    #disable_alias: true    # defaults to false
    #router_priority: 1000  # defaults to -100
    manager: es.manager.default
    seo_routes:
        'AppBundle:Product': AppBundle:Product:document
        # ...
```

> WARNING: If SeoAwareTrait is used you must implement `urlAnalyzer` analyzer, otherwise there will be a fatal error on index create.

In the configuration of the bundle you need to specify the `es.manager` to use and under the `seo_routes` you have to specify documents that will have seo\_routes as keys and the controller action that will handle the request as a values.

`urlAnalyzer` at `ongr_elasticsearch` configuration defines how all url fields are analyzed by Elasticsearch.

If you are using another third party bundle that also has an aliased Symfony router, you may set `disable_alias` to `true`. This prevents possible conflicts.

`router_priority` parameter defines the priority with which the `ONGR` dynamic router is set to the chain router. It defaults to -100 in order to be called after the standard Symfony router but this value can be changed depending on your projects' need.

Check [Elasticsearch bundle mappings docs](http://docs.ongr.io/ElasticsearchBundle/mapping) for more information about the configuration.

Usage example
-------------

[](#usage-example)

#### Step 1: Create a Product document

[](#step-1-create-a-product-document)

Lets create a `Product` document class. We assume that we have an AppBundle installed.

```
// src/AppBundle/Document/Product.php

namespace AppBundle\Document;

use ONGR\ElasticsearchBundle\Annotation as ES;
use ONGR\RouterBundle\Document\SeoAwareTrait;
use ONGR\RouterBundle\Document\SeoAwareInterface;

/**
 * @ES\Document()
 */
class Product implements SeoAwareInterface
{
    use SeoAwareTrait; //
