gpt4 book ai didi

php - Zend 路线和 SEO

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:33:14 24 4
gpt4 key购买 nike

我想知道如何使用 zend 框架实现我网站的 URL,例如 http://mysite.com/ArticleTitleHere

我看到它的方式是实现正则表达式路由,但这样 zf 将无法从常规 module/controller/actioncontroller/中分辨出文章 URL Action 路线。我将如何着手实现这样的事情?

谢谢

最佳答案

你可以在你的 route 使用占位符:

routes.test.route = "/:article"
routes.test.defaults.module = default
routes.test.defaults.controller = test
routes.test.defaults.action = test
routes.test.defaults.article = ""

您可以使用 $this->_getParam("article") 在 Controller 中检索 article 参数。其余部分(与文章名称匹配的数据库条目)由您负责。

但是你应该添加类似 url-prefix 和/或 article id 的东西,否则可能找不到其他路由。所以使用这样的东西要好得多:

routes.test.route = "/article/:id/:title"

routes.test.defaults.module = default
routes.test.defaults.controller = test
routes.test.defaults.action = test
routes.test.defaults.article = ""
routes.test.defaults.id = ""

您可以通过这种方式使用 url-Viewhelper 来创建链接:

<a href="<?php echo $this->url(array("id" => $article->id, "title" => $article->title), "test"); ?>"><?php echo $this->escape($article->title); ?></a>

并在您的 Controller 中进行重定向:

$this->_helper->redirector->gotoRoute(array("id" => $article->id, "title" => $article->title), "test");

请记住为无效字符(或非 ascii 字符)转义或过滤 $article->title

关于php - Zend 路线和 SEO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10373762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com