flarpy
(Peter)
January 23, 2015, 5:38pm
1
Been tearing my hair out on this one, I’m sure it must be possible, I want to create a rule with optional controller, as described at http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html .
Any help gratefully received on IF it is possible and if it is, how to correctly format my rule.
At URL test.mydomain.com this rule causes an ErrorException - PHP Notice – yii\base\ErrorException
Uninitialized string offset: 48
[
'pattern' => 'http://<clientname:\w+>.mydomain.com/<controller:\w+>',
'route' => 'site/index',
'defaults' => [
'controller' => 'order',
'clientname' => 'myclient'
],
],
flarpy
(Peter)
January 23, 2015, 5:42pm
2
NB. Changing <controller:\w+> to <controller:\w?> produces same error
flarpy
(Peter)
January 26, 2015, 10:23am
3
Cmon, there must be some routing guru out there
melicerte
(Recycling Spam)
January 26, 2015, 12:20pm
4
Put the whole error stack, maybe it can help.
Also, have seen this: https://github.com/yiisoft/yii2/issues/6871 ?
lukos
(Lukiebriner)
January 26, 2015, 2:41pm
5
I don’t think you can make the clientname optional as you have done above. If it is missing like:
http://mydomain.com/etc
You will not match http://<clientname:\w+>.mydomain.com/ because the . character after your clientname placeholder will still need to be matched to the URL.
The language example in the guide is similar to what you are doing but the implication is that it must always be present.
It might work if you used http://<clientname:\w+\.>mydomain.com/ but you’d have to test that.