开发者

How can I write url /:lang/display-cv-:cvid using zend_config?

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:

开发者_Python百科
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?


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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜