如何使用 zend_config 编写 url /:lang/display-cv-:cvid ?
我有一个名为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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 Zend_Controller_Router_Route_Regex。例如,对于你的情况,我认为你可以这样做:
希望这有帮助。
编辑:
ID 和反向 URL 存在错误。
You need to use Zend_Controller_Router_Route_Regex. For example, for your case I think that you could do:
Hope this helps.
EDIT:
There was a mistake with ID and a revers url.