Zend_Controller_Router_Route问题

发布于 2024-10-05 09:03:17 字数 372 浏览 0 评论 0原文

我需要修剪网址的第一部分

示例 /param1/12234/module/controller/action 会变成 /module/controller/action/param1/12234

我尝试过

$router->addRoute('appid', new Zend_Controller_Router_Route('appid/:appid/:模块/:控制器/:action/', array(), array(2=>“模块”, 3=>“控制器”, 4=>“动作”)));

但行不通!

有帮助吗?

I need to trim the first part of my url

Example /param1/12234/module/controller/action
would become /module/controller/action/param1/12234

I tried with

$router->addRoute('appid', new
Zend_Controller_Router_Route('appid/:appid/:module/:controller/:action/',
array(), array(2=> "module", 3=> "controller", 4=> "action")));

but won't works!

some helps?

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

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

发布评论

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

评论(1

愿得七秒忆 2024-10-12 09:03:17

尝试:

<?php

   //-------------------------
   // Get router from front
   // controller
   $router = $this->frontController->getRouter();

   //-------------------------
   // Create route
   $route = new Zend_Controller_Router_Route(
      'controller/action/:appid/:param1',
      array(
         'module' => default',
         'controller' => 'index',
         'action' => 'index',
         'appid' => '',
         'param1' => 'default_value'
      ),

      //-------------------------
      // You can even add a regex
      // to parameters. Example,
      // appid can only be an integer
      array(
         'appid' => '\d+'
      )
   );

   //-------------------------
   // Add route to Router
   $router->addRoute('appid', $route);
?>

当然,您需要替换一些东西(模块、控制器、操作和参数)。如果您不使用模块,只需将其从数组中删除即可。

最后,要在视图中使用路由,您可以使用:

$this->url(array('appid' => 1, 'param1' => 'custom_value'),'appid');

更新:

您可以在您的中尝试以下操作

<VirtualHost>

   RewriteEngine On
   RewriteRule ^/appid/(.*) /module/controller/action/$1 [R=301,L]
</VirtualHost>

如果您不需要使用永久 301 重定向,则可以删除 R

Try:

<?php

   //-------------------------
   // Get router from front
   // controller
   $router = $this->frontController->getRouter();

   //-------------------------
   // Create route
   $route = new Zend_Controller_Router_Route(
      'controller/action/:appid/:param1',
      array(
         'module' => default',
         'controller' => 'index',
         'action' => 'index',
         'appid' => '',
         'param1' => 'default_value'
      ),

      //-------------------------
      // You can even add a regex
      // to parameters. Example,
      // appid can only be an integer
      array(
         'appid' => '\d+'
      )
   );

   //-------------------------
   // Add route to Router
   $router->addRoute('appid', $route);
?>

Of'course, you'll need to substitute a few things (module, controller, action and parameters). If you're not using modules, simply delete it from the array.

Finally, to use the route in the view, you can use:

$this->url(array('appid' => 1, 'param1' => 'custom_value'),'appid');

UPDATE:

You can try the following in your

<VirtualHost>

   RewriteEngine On
   RewriteRule ^/appid/(.*) /module/controller/action/$1 [R=301,L]
</VirtualHost>

If you don't need to use a permanent 301 redirect, you can drop the R

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