简体   繁体   English

我如何在调度之前捕获请求的控制器/动作值?

[英]How can I catch the controller/action values of a request before dispatch?

Zend Framework: Zend框架:

I have the following url  /base/url/[number]/[string] 
OR                        /base/url/action/controller/param/value

I want in the case of /base/url/[number]/[string] to transform it to /base/url/controller/a/action/b/id/[number]/name/[string] The a and b are constants (ie each time I see a number in the place of the action, I use the same values). 我想在/base/url/[number]/[string]下将其转换为/ base / url / controller / a / action / b / id / [number] / name / [string] a和b是常量(即,每次在操作处看到数字时,我都使用相同的值)。
Where can I catch the action and controller values before they are being dispatched? 在将动作和控制器值分派之前,在哪里可以捕获它们?

You can recieve action and controller in Controller Plugin in routeShutdown() (once after route is selected) or in preDispatch() (before every controller dispatch). 您可以在routeShutdown()(一旦选择路由)中的Controller插件中或preDispatch()(在每次分发控制器之前)中接收动作和控制器。 I guess you would use routeShutdown. 我猜您会使用routeShutdown。 You have Request accessible, so you can set controller and action to anything at all.. 您可以访问“请求”,因此可以将控制器和操作设置为任何内容。

How to write plugins 如何编写插件

You can create a custom Route to handle that kind of routes, and have them dispatched to the correct controller and URL. 您可以创建一个自定义Route来处理这种路由,并将其分派到正确的控制器和URL。

For example: 例如:

$router = $front->getRouter();
$router->addRoute(
    'my_route',
    new Zend_Controller_Router_Route(
         ':number/:string',
         array(
              'controller' => 'your_controller',
              'action' => 'your_action'
         )
    )
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM