netgusto / dynamic-subdomain-bundle
Symfony2 Dynamic subdomain handler Bundle
Installs: 178
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 3
Forks: 3
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=5.3.3
This package is not auto-updated.
Last update: 2024-12-12 15:47:23 UTC
README
Install
In composer.json
:
"require": { "netgusto/dynamic-subdomain-bundle": "dev-master" }
In app/AppKernel.php
:
$bundles = array( # [...] new Netgusto\DynamicSubdomainBundle\NetgustoDynamicSubdomainBundle(), # [...] );
Configure
In app/config.yaml
netgusto_dynamic_subdomain: base_host: netgusto.com parameter_name: ~ entity: Acme\DemoBundle\Entity\MySite property: ~
-
base_host
:- The domain base host, where all subdomains are attached
- required
- example:
netgusto.com
-
parameter_name
:- The name of the parameter that will be set on the current
Request
- optional
- default value:
subdomain
- The name of the parameter that will be set on the current
-
entity
:- The class or Doctrine alias of the entity mapped to subdomains
- required
- example:
Acme\DemoBundle\Entity\MySite
-
property
:- The name of the property storing the subdomain name in your entity
- optional
- default value:
subdomain
-
method
:- The name of method that will be called to get object with the property defined
- optional
- default value:
findOneBy
Use
- Create the entities mapped to your subdomains
- Get the current subdomain object through the Symfony
Request
object
In php, assuming that netgusto_dynamic_subdomain.property
equals subdomain
(the default value):
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 netgusto_dynamic_subdomain.property
equals subdomain
(the default value), and that the entity mapped to subdomains has a title
property:
{{ 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
).