3

모두Zend Framework - 다른 모듈의 IndexController로 리디렉션

다음 프로젝트는 Zend의 mvc 프레임 워크에 있습니다. 애플리케이션에 액세스 할 때 사용자가 "default"모듈에서 IndexController로 이동하는 대신 "mobile"모듈로 리디렉션하도록합니다. 어떻게해야합니까?

-billingsystem 
-application 
    -configs 
     application.ini 
    -layouts 
     -scripts 
      layout.phtml 
    -modules 
     -default 
      -controllers 
       IndexController.php 
      -models 
      -views 
      Bootstrap.php 
     -mobile 
      -controllers 
       IndexController.php 
      -models 
      -views 
      Bootstrap.php 
Bootstrap.php 
-documentation 
-include 
-library 
-logs 
-public 
    -design 
     -css 
     -images 
     -js 
    index.php 
    .htaccess 

내 index.php에 다음 코드했습니다 컨트롤러 내에서

require_once 'Zend/Application.php'; 
require_once 'Zend/Loader.php'; 


$application = new Zend_Application(
    APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini' 
); 

$application->bootstrap()->run(); 

답변

3

은 두 가지 옵션이 있습니다 : 응용 프로그램의 기본 모듈로

1 세트 mobile 당신의 application.ini 파일을 편집하여을 resources.frontController.defaultModule = "mobile"

2 - 당신은 모든 요청을 가로 플러그인을 만들어에 전달할 수 있습니다 같은 컨트롤러와 액션 있지만 모바일 모듈

class Name_Controller_Plugin_mobile extends Zend_Controller_Plugin_Abstract { 

    public function preDispatch(Zend_Controller_Request_Abstract $request) { 

       $module = $request->getModuleName(); 
       $controller = $request->getControllerName(); 
       $action = $request->getActionName(); 
       if($module !== "mobile" || $module !== "error"){ 
        return $request->setModuleName("mobile")->setControllerName("$controller") 
        ->setActionName("$action")->setDispatched(true); 

       }else{ 
        return ; 
       } 
    } 
} 

하고 신비 루프와 끝까지하지 않도록 경우 절에 오류 컨트롤러를 추가하는 것을 잊지 마세요로 AP = 연합 뉴스 plication이 에러를 던졌습니다. 그게 전부입니다.

3

당신이 예를 들어

_forward(string $action, 
      string $controller = null, 
      string $module = null, 
      array $params = null) 

사용할 수 있습니다

$this-_forward("index", "index", "mobile"); 

이 것 색인 작업, 색인 컨트롤러로 이동 모바일 모듈은 또한 null를 사용할 수 있습니다

$this-_forward(null, null, "mobile"); 

null을 전달하면 현재의 행동과 컨트롤러를 사용합니다.

희망이 있습니다.

+0

각 컨트롤러를 변경하는 대신 index.php와 같이 전역 적으로 수행 할 방법이 없습니까? – Jake

+0

Dispatcher가 실행되기 전에 완료되도록'Zend_Controller_Plugin'에서 수행하십시오. –