开发者

Nice URL in CodeIgniter

开发者 https://www.devze.com 2023-02-15 15:29 出处:网络
does anybody knows how i can get nice url`s in 开发者_运维技巧CodeIgniter like this: examplepage.com/sites/my-new-project instead of examplepage.com/sites/2

does anybody knows how i can get nice url`s in 开发者_运维技巧CodeIgniter like this: examplepage.com/sites/my-new-project instead of examplepage.com/sites/2

The last segment in the URI can be a title oder an other custom string.

Please help me ;)

Regards,

Peter


CI's URLs are "nice" by default - you choose what they are.

Based on the idea of segments, CI has:

controller/method/params

So for instance:

class Article extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        // blah
    }

    function read($article=null)
    {
       // display article
    }
}

You can then produce links like:

site.com/article/read/my-article-title

my-article-title would be a URL slug stored in your database, which the read method will look up and return the appropriate content.

The other way as suggested is routing, but hey, the functionality is built right there so you may as well use it.


You can use routing.php for this, to set up a custom route.

http://codeigniter.com/user_guide/general/routing.html

Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消