如何使用 zend_config 编写 url /:lang/display-cv-:cvid ?

发布于 2024-11-08 05:16:41 字数 1201 浏览 1 评论 0原文

我有一个名为routes.ini 的zend_config 文件。

目前我的网址看起来像这样 /:LanguageCode/display-cv/:CVID ,

如该路由所定义:

routes.display-cv.route = /:LanguageCode/display-cv/:CVID
routes.display-cv.defaults.controller = users-profile
routes.display-cv.defaults.action = display-cv
routes.display-cv.defaults.CVID =
routes.display-cv.reqs.CVID = "\d+"
routes.display-cv.defaults.LanguageCode = 'en'
routes.display-cv.reqs.LanguageCode = "[a-z]{2}"

结果是 /en/display-cv/1

但我的老板想要这个:

/en/display-cv-1.html

我试图简单地将:更改

routes.display-cv.route = /:LanguageCode/display-cv/:CVID

为: routes.display-cv.route = /:LanguageCode/display-cv-:CVID.html 但结果是: /en/display-cv-:CVID.html。它被认为是静态网址。

然后我这样称呼它:

<?php foreach ($this->CvList as $CV){ ?>
<a href="<?php echo $this->url(array(
    'action'        => 'display-cv',
    'CVID'          => $CV->CVID,
    'LanguageCode'  => 'en'
        ),'display-cv'); ?>">
   <?php echo $CV->CvName; ?> <BR/>
   </a>
<?php }  ?>

如何更改上面的配置来实现这一点?

I got a zend_config file called routes.ini.

Currently my url looks like this /:LanguageCode/display-cv/:CVID

as defined by this route:

routes.display-cv.route = /:LanguageCode/display-cv/:CVID
routes.display-cv.defaults.controller = users-profile
routes.display-cv.defaults.action = display-cv
routes.display-cv.defaults.CVID =
routes.display-cv.reqs.CVID = "\d+"
routes.display-cv.defaults.LanguageCode = 'en'
routes.display-cv.reqs.LanguageCode = "[a-z]{2}"

which results in /en/display-cv/1

but my boss wants this instead:

/en/display-cv-1.html

I tried to simply change:

routes.display-cv.route = /:LanguageCode/display-cv/:CVID

to:
routes.display-cv.route = /:LanguageCode/display-cv-:CVID.html but the result is:
/en/display-cv-:CVID.html. it's considered a static url.

Then I call it this way:

<?php foreach ($this->CvList as $CV){ ?>
<a href="<?php echo $this->url(array(
    'action'        => 'display-cv',
    'CVID'          => $CV->CVID,
    'LanguageCode'  => 'en'
        ),'display-cv'); ?>">
   <?php echo $CV->CvName; ?> <BR/>
   </a>
<?php }  ?>

How can I change the configuration above to achieve this?

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

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

发布评论

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

评论(1

三生路 2024-11-15 05:16:41

您需要使用 Zend_Controller_Router_Route_Regex。例如,对于你的情况,我认为你可以这样做:

resources.router.routes.display-cv.route = "(.+)/display-cv-(\d+)\.html"
resources.router.routes.display-cv.type = "Zend_Controller_Router_Route_Regex" 
resources.router.routes.display-cv.defaults.controller = users-profile
resources.router.routes.display-cv.defaults.action = display-cv
resources.router.routes.display-cv.map.1 = LanguageCode
resources.router.routes.display-cv.map.2 = id
resources.router.routes.display-cv.reverse = "/%s/display-cv-%d.html"

希望这有帮助。

编辑:
ID 和反向 URL 存在错误。

routes.display-cv.route = "(.+)/display-cv-(\d+)\.html"
routes.display-cv.type = "Zend_Controller_Router_Route_Regex" 
routes.display-cv.defaults.controller = users-profile
routes.display-cv.defaults.action = display-cv
routes.display-cv.map.1 = LanguageCode
routes.display-cv.map.2 = CVID
routes.display-cv.reverse = "%s/display-cv-%d.html"

You need to use Zend_Controller_Router_Route_Regex. For example, for your case I think that you could do:

resources.router.routes.display-cv.route = "(.+)/display-cv-(\d+)\.html"
resources.router.routes.display-cv.type = "Zend_Controller_Router_Route_Regex" 
resources.router.routes.display-cv.defaults.controller = users-profile
resources.router.routes.display-cv.defaults.action = display-cv
resources.router.routes.display-cv.map.1 = LanguageCode
resources.router.routes.display-cv.map.2 = id
resources.router.routes.display-cv.reverse = "/%s/display-cv-%d.html"

Hope this helps.

EDIT:
There was a mistake with ID and a revers url.

routes.display-cv.route = "(.+)/display-cv-(\d+)\.html"
routes.display-cv.type = "Zend_Controller_Router_Route_Regex" 
routes.display-cv.defaults.controller = users-profile
routes.display-cv.defaults.action = display-cv
routes.display-cv.map.1 = LanguageCode
routes.display-cv.map.2 = CVID
routes.display-cv.reverse = "%s/display-cv-%d.html"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文