我正在尝试将我的web模板url从../blog/read/1更改为../blog/read/title-of-blog,以使用户更加友好。我一直在搜索并找到这个线程Customize dynamic URL.change ?id to name ,但是我不知道最好的方法是如何处理这个问题。我想出了两个解决方案。
1.将功能blog/read/id改为blog/read/title of blog
但这似乎会带来问题,因为如果两个博客的名字相同呢?
2.路由(来自上面链接的线程的代码)
使用数据库更新routes.php,这样每个博客都有自己的路径。在routes.php中这个应该是这样的
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->get( 'blog' );
$result = $query->result();
foreach( $result as $row )
{
$route[$row->title] = "blog/read/". $row->id;
//We suppose here that your title is URL friendly.
} 此代码不适用于我的版本,因此无法在routes.php中加载数据库。
Error: require_once(/home/x/public_html/system/database/DBEXT): failed to open stream: No such file or directory发布于 2018-06-10 17:24:25
使用SESSION是可能的。选择博客是必需的,您可以在URL中使用博客的标题,只对用户友好,不适用于博客的选择。这样你就可以用SESSION发送博客的id了。不需要编辑routes.php文件。
https://stackoverflow.com/questions/50785394
复制相似问题