1
votes

In my zend framework application, I have routes and defaults like:

resources.router.routes.plain.defaults.module = "index"
resources.router.routes.plain.defaults.controller = "index"
resources.router.routes.plain.defaults.action = "index"

I want to be able to change default routes for any module or controller or action e.g.

Let's assume this module/controller/action structure:

content --- article --- read
                    --- write
        --- news    --- list
                    --- write
user    --- auth    --- signin
                    --- signout
        --- access  --- check
                    --- update

in this architecture,

for module=content I want controller=article to be default controller and action=read to be default action.
if controller=news is chosen then action=list becomes default action

for module= user I want controller=auth to be default controller and action=signin to be default action. if controller=access is chosen then action=check becomes default action.

So is it possible to do this in application.ini? And how for this example?

Thanks in advance.

1

1 Answers

0
votes

Random Thoughts:


You could define a route for each module that points to those specific actions as defaults.

resources.router.routes.user.route = "user/:controller/:action/*"
resources.router.routes.user.defaults.module = "user"
resources.router.routes.user.defaults.controller = "auth"
resources.router.routes.user.defaults.action = "signin"

You could also define an Module_IndexController::preDispatch() or User_AccessController::indexAction() that uses _forward to send the request to the proper "default":

// delaing with the redirect in preDispatch
// will affect all requests to this controller
class User_IndexController extends Zend_Controller_Action {
  public function preDispatch() {
    // send to default location for User Module:
    $this->_forward('signin', 'auth')
  }
}

// dealing with the redirect in indexAction:
// will only affect requests that go to the "index" action
class User_AccessController extends Zend_Controller_Action {
  public function indexAction() {
    // send to default location for User Module:
    $this->_forward('check')
  }
}

From Zend Framework Documentation - Controller Utility Methods

_forward($action, $controller = null, $module = null, array $params = null): perform another action. If called in preDispatch(), the currently requested action will be skipped in favor of the new one. Otherwise, after the current action is processed, the action requested in _forward() will be executed.