如何在Codeigniter中进行分类? [英] How to do categories in Codeigniter?
本文介绍了如何在Codeigniter中进行分类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将帖子所属的类别存储在数据库中,并希望在URL中使用它们。我该如何动态地做到这一点?
I store the categories that a post belongs to in a database and I'd like to use them in the URL. How can I do this dynamically?
例如,我想生成一个类似example.com/action-adventure/post-name的URL。
For example, I'd like to generate a URL like example.com/action-adventure/post-name.
我想它会涉及routes.php,但我只是不知道如何动态地做到这一点。
I'd imagine it would involve routes.php, but I just don't know how to do it dynamically.
推荐答案
这可能有问题,请考虑:
This could be problematic, consider:
$route['(:any)'] = 'blog/post/$1';
$route['(:any)/(:any)'] = 'blog/post_category/$1/$2';
-
$route['(:any)'] = 'category/$1';
博客/帖子在此处具有优先权,因此命名约定成为一个问题/或者不是
Blog/post would have priority here, so naming conventions become an issue/or not
事先构造链接,我建议
public function post_category($type, $post_name){}
这篇关于如何在Codeigniter中进行分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文