【发布时间】:2016-09-13 14:34:18
【问题描述】:
我有动作“显示”用于在博客中显示 URL 为:localhost/myblog/web/blog/blog/post?id=4 的文章。
我希望 URL 为 localhost/myblog/web/blog/blog/post/unique/title-of-article。如何完成这样的事情?
【问题讨论】:
我有动作“显示”用于在博客中显示 URL 为:localhost/myblog/web/blog/blog/post?id=4 的文章。
我希望 URL 为 localhost/myblog/web/blog/blog/post/unique/title-of-article。如何完成这样的事情?
【问题讨论】:
您必须在模型中使用 SluggableBehavior 来生成人类可读的 url 部分。此数据保存保存到您的数据库模型中。 通过这个 slug 以及对控制器和 UrlManager 规则的一些修改,您可以创建您想要的内容。
这将是一个完整的教程,这是 Stackoverflow 上的 already answered。 如果您需要更详细的教程,我会建议谷歌。可以轻松找到多个教程,例如this。
【讨论】: