Zend 框架模块、控制器、操作特定路线

发布于 2024-09-26 03:55:17 字数 871 浏览 0 评论 0原文

在我的 zend 框架应用程序中,我有路由和默认值,例如:

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

我希望能够更改任何模块、控制器或操作的默认路由 例如,

让我们假设这个模块/控制器/操作结构:

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

在这个架构中,

对于我想要的模块=内容 controller=article 作为默认控制器并且 action=read 为默认操作。
如果选择了controller=news,那么action=list将成为

我想要的module=用户的 默认操作 controller=auth 为默认控制器,action=signin 为默认操作。 如果选择controller=access,则action=check 将成为默认操作。

那么可以在application.ini中做到这一点吗?这个例子又如何呢?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的往事 2024-10-03 03:55:17

随机想法:


您可以为每个模块定义一条默认指向这些特定操作的路由。

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"

您还可以定义 Module_IndexController::preDispatch()User_AccessController::indexAction() ,使用 _forward 将请求发送到正确的“ 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')
  }
}

来自 Zend 框架文档 - 控制器实用方法

_forward($action, $controller = null, $module = null, array $params = null):执行另一个操作。如果在 preDispatch() 中调用,当前请求的操作将被跳过,转而执行新的操作。否则,在处理当前操作后,将执行_forward()中请求的操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文