문제

ZF2를 사용하여 다중 언어 응용 프로그램을 작성하고 있습니다. 모듈에 관계없이 각 URL의베이스를 형성하는 파트 URL을 추가하는 방법을 결정할 수 없습니다.

http://localhost/en/us/application/index/index/
.

di 를 사용하여 /[:namespace[/:controller[/:action]]]를 구성하는 방법을 완전히 이해합니다.

http://localhost/application/index/index/
http://localhost/guestbook/index/index/
http://localhost/forum/index/index/
.

내가 이해하지 못하는 것은 파트 경로를 구성하는 방법입니다. zf1에서 경로 체인 을 사용하여 route in 을 사용했습니다.

사이트 와이드를 적용한 다음 모듈을 구성하는 Per /[:lang[/:locale]] part part 경로를 구성해야합니다.

http://localhost/en/us/application/index/index/
http://localhost/zh/cn/application/index/index/
http://localhost/en/uk/forum/index/index/
.

도움이 되었습니까?

해결책

나는 당신이 찾고있는 것이 child_routes 구성 키라고 생각합니다. zfcuser 구성하는 방법을 살펴보십시오.) : 기본 리터럴 라우트 (/ user)를 생성 한 다음 Sub-routes (/ user / login 등)를 child_routes 배열을 통해이를 통해 사슬입니다.

나는 이것이 당신을 위해 트릭을 할 것이라고 생각합니다.

'router' => array(
    'routes' => array(
        'myapp' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/[:lang[/:locale]]',
                'defaults' => array(
                    'lang'   => 'en',
                    'locale' => 'us',
                ),
            ),
            'may_terminate' => false,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                    ),
                    'defaults' => array(
                        'controller' => 'index',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),
),
.

그런 다음 컨트롤러에서 Lang과 Locale을 얻으려면이 작업을 수행 할 수 있습니다.

$this->params()->fromRoute('lang');
$this->params()->fromRoute('locale');
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top