gpt4 book ai didi

php - 'router' - 如何使其正确?

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:00 25 4
gpt4 key购买 nike

我想问你路由器的最佳解决方案。

我的数据库中有一些表(文章、页面、类别等),它们都有 ID。我想为他们每个人生成特定的 URL,例如。 /en/article/25-This-is-an-test-article.

但是如何摆脱那个/article/page,...?用户不希望看到它 - 它只会增加 url 的长度...

我的第一个想法是简单的路由表:

CREATE TABLE `router` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`type` varchar(50) NOT NULL,
`entity_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;

但是有一个致命的问题——无法为 enitity_id 列设置外键,因为它应该引用更多的列,而这在 SQL 中是不可能的。

我的问题是:你认为我应该坚持那个解决方案吗(忽略外键)或者我应该忘记它并在 URL 中附加类型?

最佳答案

I want /en/article/55-something to become /en/55-something - with the best performance, with the best and cleanest way (the problem is WHERE and HOW to save the info that 55-something IS an article, not the page)

该信息的最佳位置就在 URL 中,这样您就不必为脆弱的、最佳猜测的查找而烦恼。

简短回答:您已经正确地做到了。

关于php - 'router' - 如何使其正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7047623/

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