小编Ale*_*nko的帖子

Symfony2:如何:使用_locale保护应用程序

所有!我想用安全系统一起保护我的应用程序.在security.yml文件下面

security:
  encoders:
    Symfony\Component\Security\Core\User\User: plaintext

  role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

  providers:
    in_memory:
      users:
        user:  { password: userpass, roles: [ 'ROLE_USER' ] }
        admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }

  firewalls:
    dev:
      pattern:  ^/(_(profiler|wdt)|css|images|js)/
      security: false

    login:
      pattern:  ^/{_locale}/demo/secured/login$
      security: false

    secured_area:
      pattern:    ^/{_locale}/demo/secured/
      form_login:
        check_path: /{_locale}/demo/secured/login_check
          login_path: /{_locale}/demo/secured/login
        logout:
          path:   /{_locale}/demo/secured/logout
          target: /{_locale}/demo/
Run Code Online (Sandbox Code Playgroud)

问题:

注销 - >目标返回不起作用.有人能帮助我吗?

PS:任何例子都将不胜感激!

谢谢

php security localization internationalization symfony

9
推荐指数
1
解决办法
8164
查看次数

Symfony2:没有会话/控制器的Locale Switcher实现

所以,3.5小时后似乎一切都好......

两页:

localhost.lo/XX /约

localhost.lo/XX /你好/(名称)

其中xx - routing.yml中描述的几个语言环境

- routing.yml

home:
    resource: "@JetInformBundle/Resources/config/routing.yml"
    prefix: /{_locale}
    requirements:
        _locale: ^en|de|ru|uk|pl$
Run Code Online (Sandbox Code Playgroud)

- JetInformBundle routing.yml

hello:
    pattern:  /hello/{name}
    defaults: { _controller: JetInformBundle:Default:index, name: 'alexander' }

about:
    pattern:  /about
    defaults: { _controller: JetInformBundle:Default:about }
Run Code Online (Sandbox Code Playgroud)

- DefaultController.php

<?php

namespace Jet\InformBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    public function indexAction($name, Request $request)
    {
        return $this->render('JetInformBundle:Default:index.html.twig',
                             array('name' => $name, 'matches' => $this->matchAction($request)));
    }

    public function aboutAction(Request $request)
    {
        return $this->render('JetInformBundle:Default:about.html.twig', …
Run Code Online (Sandbox Code Playgroud)

php localization symfony

6
推荐指数
0
解决办法
2126
查看次数

Symfony2:与Request对象类似的Referrer对象?

我正在努力找到一个"引用者"对象,以便在我的控制器中使用.我希望有一个类似于请求对象的对象,其参数指定_controller,_route和arguments.

我想要做的是一个语言切换器操作,将用户重定向到新语言的同一页面.有点像:

public function switchLangAction($_locale)
{
    $args = array();
    $newLang = ($_locale == 'en') ? 'fr' : 'en';

    // this is how I would have hoped to get a reference to the referrer request.
    $referrer = $this->get('referrer');
    $referrerRoute = $referrer->parameters->get('_route');
    $args = $referrer->parameters->get('args'); // not sure how to get the route args out of the params either!
    $args['_locale'] = $newLang;

    $response = new RedirectResponse( $this->generateUrl(
        $referrerRoute,
        $args
    ));

    return $response;
}
Run Code Online (Sandbox Code Playgroud)

也有可能有另一种方法来做到这一点 - 我知道在rails中有例如"redirect_to:back"方法.

任何帮助将不胜感激.

php localization symfony

5
推荐指数
1
解决办法
8613
查看次数

HAProxy 平衡器使用 url_param 值?

我有 3 个不同的 Restful 服务器:w1、w2、w3

引用我的负载均衡器的客户端提供名为“ip”(ipv4) 的 url 参数。请求之间的 url 参数 ip 是不同的:

curl -XGET http://localhost:8080/api/v1/link?ip=x.x.x.x
Run Code Online (Sandbox Code Playgroud)

我想使用 HASH 算法根据 ip 参数平衡 HAProxy 到 w1、w2、w3。

HAProxy 配置如下:

global
    #daemon
    maxconn 3000

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http-in
    bind *:80
    default_backend workers

backend workers
    balance url_param ip
    hash-type consistent
    server w1 localhost:8080 weight 1 maxconn 1000 check
    server w2 localhost:8081 weight 1 maxconn 1000 check
    server w3 localhost:8082 weight 1 maxconn 1000 check

listen …
Run Code Online (Sandbox Code Playgroud)

hash load-balancing haproxy

5
推荐指数
1
解决办法
2808
查看次数

Symfony2:子域之间的透明授权过程

所有!

我只是看到symfony2路由器不使用uri的主机部分.我需要将COUNTRY分隔为第三个子域,将locale分隔为路径路径中的第一个元素

http:// {country} .mysite.com/{_locale}/myaction,即

en.mysite.com/en/action ---英语公司和英语

de.mysite.com/ru/action --- deutschland公司和俄语

ru.mysite.com/uk/action ---俄罗斯公司和乌克兰语

通过以下服务解决了这个问题:

-- config.yml

services:
   kernel.listener.subdomain_listener:
       class: Acme\DemoBundle\Listener\SubdomainListener
       tags:
           - { name: kernel.event_listener, event: kernel.request, method: onDomainParse }

-- SubdomainListener.php

<?php

namespace Acme\DemoBundle\Listener;

use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;

class SubdomainListener
{
   public function onDomainParse(Event $event)
   {
       $request = $event->getRequest();
       $session = $request->getSession();

       // todo: parsing subdomain to detect country

       $session->set('subdomain', $request->getHost());
   }
}
Run Code Online (Sandbox Code Playgroud)

但是......问题是:如何在几个子域之间透明地实现AUTH进程一次只能进行一次?

  1. 用户通过en.mysite.com/{_ locale}/...登录

  2. 用户访问de.mysite.com/{_ locale}/...但是系统知道他(她)并且没有再次询问登录/密码凭据

有人帮帮我吗?谢谢你提前!认证高级Oracle开发人员/ DBA

php subdomain authorization symfony

2
推荐指数
1
解决办法
3440
查看次数

Symfony2:在切换区域设置期间向后Uri(推荐人)

我想实现区域设置切换器,但似乎没有运气...

下面的代码不起作用,因为(Referrer)包含旧的locale值...

如何使用新的locale值重定向到旧的Referrer URI?

- routing.yml

hello:
  pattern:  /{_locale}/hello/{name}
  defaults: { _controller: JetInformBundle:Default:index, name: 'alexander' }
  requirements:
    _locale: ^en|de|ru|uk$

about:
  pattern:  /{_locale}/about
  defaults: { _controller: JetInformBundle:Default:about }
  requirements:
    _locale: ^en|de|ru|uk$

locale:
  pattern:  /locale/{locale}
  defaults: { _controller: JetInformBundle:Locale:index }
Run Code Online (Sandbox Code Playgroud)

- DefaultController.php

<?php

namespace Jet\InformBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    public function indexAction($name, Request $request)
    {
        $request->getSession()->set('referrer', $request->getRequestUri());
        return $this->render('JetInformBundle:Default:index.html.twig',
                             array('name' => $name));
    }

    public function aboutAction(Request $request)
    {
        $request->getSession()->set('referrer', $request->getRequestUri());
        return $this->render('JetInformBundle:Default:about.html.twig'));
    } …
Run Code Online (Sandbox Code Playgroud)

php localization referrer symfony

1
推荐指数
1
解决办法
1万
查看次数