自定义动态URL.change?id以命名 [英] Customize dynamic URL.change ?id to name

查看:130
本文介绍了自定义动态URL.change?id以命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用codeigniter创建动态网站。在新闻页面中,我使用url方法,例如: http://test.com/test/test/news_details?id=27

I'm using codeigniter for make dynamic website. In news page, I use url method like: http://test.com/test/test/news_details?id=27

如何更改我的URL以将新闻标题放在中?id = 27

how can i change my url to put news title within ?id=27

示例:

http://test.com/test/test/news_details/pass-this-url

传递此网址是id = 27。

"pass-this-url" refer to id=27.

最好的问候。

推荐答案

使用路线: http://www.codeigniter.com/user_guide/general/routing.html

在您的情况下会是这样的:

In your case it will be something like this :

$route['pass-this-url'] = "test/test/news_details?id=27";

所以 http://www.example.com/pass-this-url 将被codeigniter理解为 http://www.example.com/test/test/news_details?id=27

So http://www.example.com/pass-this-url will be understand by codeigniter as http://www.example.com/test/test/news_details?id=27

但是,如果要使其动态,则必须调用数据库:

however, if you want to make it dynamic, you will have to call your db :

require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->get( 'news' );
$result = $query->result();
foreach( $result as $row )
{
    $route[$row->title] = "test/test/news_details?id=". $row->id;
    //We suppose here that your title is URL friendly.
} 

这篇关于自定义动态URL.change?id以命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆