Please wait for 15 seconds...

Monday, 17 September 2012



In codeigniter the default URL is something like this

http://www.mygreatsite.com/index.php/video/display/12345

I will explain you here how to customise above URL in codeigniter.

Suppose you have a video hosting site and controller class named "Video" and its method named "display".

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Video extends CI_Controller {
public function display(){
// display video
}
}



To display video you have to pass video ID through URL. By default setting URL will look like this

http://www.mygreatsite.com/index.php/video/display/video_id

I would recommend you to remove index.php first so URL would look like this.

http://www.mygreatsite.com/video/display/video_id

Now lets jump to application/config/routes.php and open it in Notepad or Notepad++. Copy below code and paste it at the bottom of the page. Remember below code is just an example. You should use it based on your project requirement.

If video ID is an integer like 12345


$route['show/(:num)'] = "video/display/$1";

If video ID is an string like vid123


$route['show/(:any)'] = "video/display/$1";

So the new URL will be like something like this

http://www.mygreatsite.com/show/vid123

So you can pass video ID as integer or string in both scenario it will work fine.

That it all for now see you in next tutorial.

Posted by Atul Prasad Gupta

10 comments:

  1. Thanks for the above information about customization url in codeigniter by giving a description and letting the customer know about the codeigniter.

    ReplyDelete
    Replies
    1. Thank for comment. I hope other tutorials will not disappoint you.

      Delete
  2. Thanks for details about personalization url in codeigniter by providing a details and allowing the client know about the codeigniter.

    ReplyDelete
  3. I wasn’t aware of some of the information that you mentioned so I want to just say thank you.

    ReplyDelete
  4. I do agree with all the ideas you have presented in your post. They are very convincing and will definitely work. Thanks for the post.

    ReplyDelete
  5. thanks for your help i am new on this framework and it help me very much

    ReplyDelete

Subscribe Techsirius

Techsirius on Facebook