Peter
Peter

Reputation: 683

Nice URL in CodeIgniter

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

Upvotes: 0

Views: 504

Answers (2)

Ross
Ross

Reputation: 17987

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.

Upvotes: 1

Joris Ooms
Joris Ooms

Reputation: 12048

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

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

Good luck.

Upvotes: 1

Related Questions