I'm inclined to side with Anders on this matter. It's better to force
a redirect, as this would ensure that your url's are canonical (eg.
you don't have two url's to point to the same resource). Note that you
can use requestUri(), rather than the global variable $_SERVER.
If you really wanted to have ambiguous url's you could implement it by
having your root component extend from the language-segment component.
Eg.:
class LanguageSegmentComponent extends k_Component {
protected function map($name) {
switch ($name) {
case 'foo':
return 'FooComponent';
}
}
function getLanguage() {
return $this->name;
}
}
class Root extends LanguageSegmentComponent {
protected $valid_languages = array('en','se');
protected function map($name) {
if (in_array($name, $this->valid_languages)) {
return 'LanguageSegmentComponent';
}
return parent::map($name);
}
function getLanguage() {
return $this->valid_languages[0];
}
}
class FooComponent extends k_Component {
function renderHtml() {
return sprintf("<h1>Foo</h1><p>Selected language is:
<b>%s</b></p>", htmlspecialchars($this->context->getLanguage()));
}
}
I didn't test the above code, so I may have missed a typo or so. In
any case, I would suggest that you follow Anders' suggestion.
--
troels