Subsystems
You can divide your web application into multiple subsystems, for which you can define separate controllers. This is useful, for example, if your web application comprises several domains.
Configuring Subsystems
You can configure subsystems in the app.ini. Host name and application context path (URL path to n2n-public) are available as criteria:
[routing-foo]
host = "www.example.com"
[routing-bar]
host = "n2n.rocks"
In this example we defined the two subsystems "foo" and "bar". Depending on whether the web application is called via www.example.com or n2n.rocks, the subsystem "foo" or "bar" is active. If your web application is called via a different domain, no subsystem is active.
Using the application context path as a criterion, you can further restrict subsystems:
[routing-foo]
host = "www.example.com"
context_path = "/"
[routing-bar]
host = "n2n.rocks"
context_path = "/public1"
[routing-baz]
host = "n2n.rocks"
context_path = "/public2"
Via n2n\web\http\Request::getSubsystem() you can query the current subsystem.
Controllers for Subsystems
Separate controllers can be defined for subsystems:
[routing]
controllers[] = "/notexample > atusch\controller\NotExampleController"
controllers[] = "/example > atusch\controller\ExampleController"
[routing-foo]
controllers[] = "/example > atusch\controller\FooExampleController"
[routing-bar]
controllers[] = "/example > atusch\controller\BarExampleController"
If no subsystem is active, the ExampleController is executed when http://.../example is called. If the subsystem "foo" or "bar" is active, however, it is overwritten by FooExampleController or BarExampleController. NotExampleController, on the other hand, can always be called, regardless of which subsystem is active.
Testing Locally
To test subsystems with host names on the local machine, you can define alternative host names for development mode:
[http : development]
subsystems.foo.host = "localhost.example.com"
subsystems.bar.host = "localhost.n2n.rocks"
You can now add A records with the IP 127.0.0.1 to the DNS server for these domains. Alternatively, simply add these host names to the hosts file of your operating system (Windows: C:\Windows\System32\drivers\etc, Mac OS: /private/etc/hosts, Linux: /etc/hosts):
127.0.0.1 localhost.example.com
127.0.0.1 localhost.n2n.rocks
You can now call the local host via localhost.example.com or localhost.n2n.rocks.
Forcing a Subsystem
In the index.php of n2n you will find the instruction n2n\N2N::autoInvokeControllers();. It executes the controllers, but determines the subsystem itself. If you use invokeControllers() instead, you can determine the active subsystem yourself:
n2n\N2N::invokeControllers('foo');
If you do not pass a subsystem name or null, no subsystem is active.