the website I'm working on has a regular/desktop and a mobile version.
For the regular version, routing is easy because I don't have to care about
the domain name.
For the mobile version however, it's different because the domain name is the thing that tells Nette that it should process the request with module MobileModule.
I have a fake tld .pp defined on my workstation to distinguish my development version from the live server. I tried several ways to define routing for the mobile version for both domains but none of them does what I want without some show stopping side effect.
Here's what I tried:
<?php // Mobile version $container->router = $mobileRouter = new NRouteList('Mobile'); $mobileRouter = new NRoute('//m.example.cz/<action>[/<id>]', 'Page:default'); $mobileRouter = new NRoute('//m.example.pp/<action>[/<id>]', 'Page:default'); // Desktop version $container->router = new NRoute('<presenter>/<action>[/<id>]', 'Default:default'); ?>
Problem: Redirects m.example.pp to m.example.cz. I want .pp to stay on .pp and .cz to stay on .cz.
I also tried foo parameters:
<?php $mobileRouter = new NRoute('//m.example.<? pp|cz>/<action>[/<id>]', 'Page:default'); ?>
Problem: Redirects to “m.example.”. (no tld at the end, just a dot)
I tried adding a parameter in place of the tld even though I don't need to use it in my presenter:
<?php $mobileRouter = new NRoute('//m.example.<domain>/<action>[/<id>]', 'Page:default'); ?>
Problem: Links contain a presenter name (mobile.page) in their url although this route doesn't contain a placeholder for presenter. I suppose they are in fact made with the desktop version route but I don't understand why. The two previous attempts didn't do that. I want short addresses like m.example.pp/contact-us
Any ideas, guys?
Last edited by petr.pavel (2013-01-11 10:27)
It didn't help. Besides, my route already contains a default presenter and
By the way, I cannot specify a default domain because then links lead to the
default domain instead of to the current one. Weird but true. With
'domain' => 'cz' I can load home page for m.example.pp (it
doesn't redirect) but all links point to m.example.cz.
It's actually kinda funny and I'm beginning to suspect a bug in Nette.
I just noticed that with default domain = cz, the links at .pp do lead to .cz however, at least they don't contain the presenter name!
Upon visiting m.example.pp, a typical link looks like this:
When I remove the default domain in order to stay on .pp, the links change
Interesting, isn't it.
BTW: Nette Framework 2.0.6 (revision 6a33aa6 released on 2012–10–01)
- Moderator | 1154
I've read just the code parts, so sry if I skipped something that had been already said.
This works for me:
$container->router = new NRoute('//example.<domain com|ble>/<presenter>/<action>[/<id>]', array( 'domain' => 'com', 'presenter' => 'Homepage', 'action' => 'default' ));
I can load the same content from
This works as well (oh I was so lazy to do that):
$container->router = new NRoute('//example.<domain com|ble>/<presenter>/<action>[/<id>]', 'Homepage:default');
@Schmutzka: Thanks for the effort but either I missed your point or you didn't bring anything new.
I've already tried using <domain> parameter (my version 3). The only difference in your code was that you listed all possible values (com|ble). I tried that too but it didn't resolve my problem with presenter name in the url.
Perhaps you'll have time later to read the non-code parts as well and test with a route that does not contain a presenter (see my routes in the first post).