I want to ask you for best solution for the router.
I have some tables in my database (articles, pages, categories etc.) which all has IDs.
I want to generate specific URL for each of them, eg. /en/article/25-This-is-an-test-article.
But how to get rid of that /article, /page, … ? Users don’t want to see it – it just increases the length of url …
My first idea was simple router table:
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;
But there is one fatal problem – It’s impossible to set foreign key for the enitity_id column because it should refer to more columns and that is not possible in SQL.
My question is:
Do you think that I should stick with that solution (and ignore the foreign key )
or should I forgt about it and append the type in the URL ?
The best place for that information is right there in the URL, so that you don’t have to muck about with flimsy, best-guess lookups.
Short answer: you’re already doing it properly.