zend mod 重写或路由

发布于 2024-10-01 04:16:18 字数 372 浏览 0 评论 0原文



我在我的 Web 应用程序中使用 Zend Framework。我有下一个 URL:domain/user/user/username。其中第一个 userdefault 模块中的控制器。第二个 user 是一个 GET 变量。 username 是该变量的值。一切都好。但为了良好的可用性,我想要下一个 URL:domain/user/username。我知道根据 Zend GET 规则,它应该作为我的第一个变体。但也许我可以通过 mod 重写或 Zend_Route 来做到这一点?请帮助我。

提前谢谢您。

I use Zend Framework in my web application. I have the next URL: domain/user/user/username. Where first user is a controller in the default module. Second user is a GET variable. username is a value of this variable. All good. But for the good usability I want to have the next URL: domain/user/username. I know that by Zend GET rules it should be as my first variant. But maybe I can do this with mod rewriting or Zend_Route? Help me, please.

Thank you in advance.

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

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

发布评论

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

评论(2

甜嗑 2024-10-08 04:16:18

创建/application/configs/routes.xml

<?xml version="1.0" encoding="UTF-8"?>
<routes>
    <user>
      <route>user/:username/*</route>
      <defaults>
          <module>default</module>
          <controller>user</controller>
          <action>view</action>
          <username>0</username>
      </defaults>
    </user>
</routes>

然后在Bootstrap.php中:

public function _initRouter()
{
    $front = Zend_Controller_Front::getInstance();
    $router = $front->getRouter();
    $config = new Zend_Config_Xml(dirname(__FILE__) . '/configs/routes.xml');
    $router->addConfig($config);

    return $router;
}

您还可以通过许多其他方式执行相同的操作,例如在application中。 ini.

Create /application/configs/routes.xml:

<?xml version="1.0" encoding="UTF-8"?>
<routes>
    <user>
      <route>user/:username/*</route>
      <defaults>
          <module>default</module>
          <controller>user</controller>
          <action>view</action>
          <username>0</username>
      </defaults>
    </user>
</routes>

Then in Bootstrap.php:

public function _initRouter()
{
    $front = Zend_Controller_Front::getInstance();
    $router = $front->getRouter();
    $config = new Zend_Config_Xml(dirname(__FILE__) . '/configs/routes.xml');
    $router->addConfig($config);

    return $router;
}

You may also do the same in a lot of other ways, e.g. in application.ini.

愿与i 2024-10-08 04:16:18

在您的 application.ini 中,添加:

resources.router.routes.article.type = "Zend_Controller_Router_Route"
resources.router.routes.article.route = "user/:username/*"
resources.router.routes.article.defaults.module = "default"
resources.router.routes.article.defaults.controller = "user"
resources.router.routes.article.defaults.action = "view"
resources.router.routes.article.reqs.username = "guest"

我建议您查看:

http://framework.zend.com/manual/en/zend.controller.router.html

In your application.ini, add:

resources.router.routes.article.type = "Zend_Controller_Router_Route"
resources.router.routes.article.route = "user/:username/*"
resources.router.routes.article.defaults.module = "default"
resources.router.routes.article.defaults.controller = "user"
resources.router.routes.article.defaults.action = "view"
resources.router.routes.article.reqs.username = "guest"

and I suggest you to have a look at:

http://framework.zend.com/manual/en/zend.controller.router.html

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