Zend Framework - redirect to IndexController in another module

All,

I have the following project setup in Zend mvc Framework. When accessing the application, I want the user to be redirected to the "mobile" module instead of switching to the "default" module in IndexController. How to do it?

-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

My index.php has the following code:

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
source share
2 answers

You have two options:

1- set mobileas the default module for your application by editing the application.ini file resources.frontController.defaultModule = "mobile"

2- you can create a plugin that intercepts every request and redirects it to the same controller and action, but to the mobile module

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 ;
                 }
    }
}

if, , ,

+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 .

, .

+3

All Articles