2017 © Pedro Peláez
 

symfony-bundle dynamic-subdomain-bundle

Symfony3 Dynamic subdomain handler Bundle

image

senj/dynamic-subdomain-bundle

Symfony3 Dynamic subdomain handler Bundle

  • Sunday, February 26, 2017
  • by senj
  • Repository
  • 1 Watchers
  • 1 Stars
  • 81 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

Dynamic subdomain handler for Symfony 3

Install

In composer.json:, (*1)

"require": {
    "senj/dynamic-subdomain-bundle": "dev-master"
}

In app/AppKernel.php:, (*2)

$bundles = array(
    # [...]
    new Senj\DynamicSubdomainBundle\SenjDynamicSubdomainBundle(),
    # [...]
);

Configure

In app/config.yaml, (*3)

senj_dynamic_subdomain:
    base_host: domain.com
    parameter_name: ~
    entity: Acme\DemoBundle\Entity\MySite
    property: ~
  • base_host:, (*4)

    • The domain base host, where all subdomains are attached
    • required
    • example: domain.com
  • parameter_name:, (*5)

    • The name of the parameter that will be set on the current Request
    • optional
    • default value: subdomain
  • entity:, (*6)

    • The class or Doctrine alias of the entity mapped to subdomains
    • required
    • example: Acme\DemoBundle\Entity\MySite
  • property:, (*7)

    • The name of the property storing the subdomain name in your entity
    • optional
    • default value: subdomain
  • method:, (*8)

    • The name of method that will be called to get object with the property defined
    • optional
    • default value: findOneBy

Use

  1. Create the entities mapped to your subdomains
  2. Get the current subdomain object through the Symfony Request object

In php, assuming that senj_dynamic_subdomain.property equals subdomain (the default value):, (*9)

use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller {

    public function indexAction(Request $request) {
        $subdomainobject = $request->attributes->get('subdomain');
        var_dump($subdomainobject);
    }

In twig, assuming that senj_dynamic_subdomain.property equals subdomain (the default value), and that the entity mapped to subdomains has a title property:, (*10)

{{ app.request.attributes.get('subdomain').title }}

Notes

If the subdomain is not found in the database, an exception will be thrown by the Bundle (Symfony\Component\HttpKernel\Exception\NotFoundHttpException)., (*11)

The Versions

26/02 2017

dev-master

9999999-dev https://github.com/senj-gold/dynamic-subdomain-bundle

Symfony3 Dynamic subdomain handler Bundle

  Sources   Download

MIT

The Requires

 

by Sergey Zheleznyak

symfony subdomain

26/02 2017

1.0.0

1.0.0.0 https://github.com/senj-gold/dynamic-subdomain-bundle

Symfony3 Dynamic subdomain handler Bundle

  Sources   Download

MIT

The Requires

 

by Sergey Zheleznyak

symfony subdomain