Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Firewall] No routing and locale support #861

Closed
adrianrudnik opened this issue May 9, 2011 · 8 comments
Closed

[Firewall] No routing and locale support #861

adrianrudnik opened this issue May 9, 2011 · 8 comments

Comments

@adrianrudnik
Copy link
Contributor

Simple use-case:

#app/config/routing.yml

languageselector:
    pattern:      /

frontpage:
    pattern:      /{_locale}
    requirements: { _locale: en|fr|de, _scheme: http }

and

#app/config/security.yml
    firewalls:
        public:
           ...
            form_login:
                check_path: ?
                login_path: ?
                default_target_path: ?
            logout:
                path: ?
                target: ?

The backrouting is very limited. Neither will work for the ? placeholder: /{_locale}, frontpage, /{_locale}/login.
I'm new to Symfony maybe im missing something but my general understanding from the docs was that routing is the main component that all other should rely on. This seems like a serious limitation for localized sites as I need to route the user through the languageselector route to get him back to the frontpage (or any localized page).

@Seldaek
Copy link
Member

Seldaek commented May 9, 2011

The "?" placeholder there is in fact regular expression paths, and not routing related. Therefore you should use something like: /[a-z]{2}/login for example, which should match /en/login and /de/login etc.

@stof
Copy link
Member

stof commented May 9, 2011

@Seldaek the issue is that the login_path is used to redirect the user (as for default_target_path). It is not a regular expression

@adrianrudnik
Copy link
Contributor Author

How can i determine if it should be en or de? I need to redirect the user to his "control panel" /{_locale}/account after a sucessfull login.

@Seldaek
Copy link
Member

Seldaek commented May 9, 2011

Ah sorry, I guess I misunderstood your question. This is indeed a problem for which there is no good solution atm I'm afraid. What you can try is this:

account:
    pattern:      /{_locale}/account
    defaults: { ... }

_post_login:
    pattern:      /account
    defaults: { _controller: FrameworkBundle:Redirect:redirect, route: 'account' }

That way if all goes well if you point the target_path to /account, it will redirect and use the session's locale to generate the url to /xx/account.

The other solution, that's maybe less hackish, would be to specify the "_target_path" (iirc) as a hidden form field in your login form, and generate the proper url based on the current locale.

@adrianrudnik
Copy link
Contributor Author

Thanks for the workaround. I will try the redirection approach as it seems more controllable. Should i leave this open as a a feature request?

@Seldaek
Copy link
Member

Seldaek commented May 9, 2011

Make sure it works before thanking me ;) As for the feature, considering the configuration value is only a default and the actual value should be given in the form, I guess yes, if it's solved for you you can close this, and if you feel like being real nice you could head to https://github.com/symfony/symfony-docs and submit a pull request to improve the docs about this :)

@schmittjoh
Copy link
Contributor

{_locale} can now be used as placeholder in the target path.

@Seldaek
Copy link
Member

Seldaek commented May 16, 2011

@schmittjoh looks like this code was never merged? Also I think you're misusing strtr() there, it should be strtr($this->determineTargetUrl($request), array('{_locale}', $session->getLocale())); or better just use str_replace in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants