1

in basic i have a table category like

|id|name    |
|1 |home    |
|2 |tutorial|
...

and table posts like

|id|name           |cateID|
...
|5 |getting started|2
...

1. if i view(click) tutorial in category, then url will be like

`index.php/nameOfControllerFile/functionName/2`

2 is id of table category .

But i see all of website i view. it look like

category/tutorials.htm or like category/tutorials/

2. and if i view getting started Post, then url will be like

index.php/nameOfControllerFile/functionName/5

5 is id of table posts.

But i see all of website i view. it look like

category/tutorials/getting-started.htm

Here is website like struction http://line25.com/category/tutorials

How can i change basic url to url like above ?

Edit

What is heppend if has two posts is the same title like

|id|name           |cateID|
...
|5 |getting started|2
|8 |getting started|2 
...
DeLe
  • 2,442
  • 19
  • 88
  • 133
  • 1
    .HTACCESS will help you to rewrite the URL – jcho360 Sep 06 '13 at 17:19
  • You should clarify the question, if it really is how to use name instead of id then it's pretty simple, query for name instead if id... – JimL Sep 06 '13 at 17:20

4 Answers4

0

Please refer to Codeigniter's help docs on this found here:

http://ellislab.com/codeigniter/user-guide/general/urls.html

See the section named Removing the index.php file

tommyd456
  • 10,443
  • 26
  • 89
  • 163
0

It's done via .htaccess file in apache server, re-writing the url (mod rewrite), for example:

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php

Above line will look for a file with .php extension when you give a url with .html, it means, if you write home.html in the address bar then the server will look for the home.php file and will launch it. Check this and this one too.

Also, for CodeIgniter, you may check this answer.

Community
  • 1
  • 1
The Alpha
  • 143,660
  • 29
  • 287
  • 307
0

.HTACCESS will help you to rewrite the URL But you have to change route file in config according to your .HTACCESS file.

manish
  • 1
  • 1
0

No clue what you are asking. Might be routes. Check it:

Say you have a controller called tutorials. In that controller you have a view function to view a specific tutorial, and an index function for the tutorials homepage where you can see all of the tutorials as in the line25 link you showed.

NOTE: see https://stackoverflow.com/a/9667306/183254, https://www.google.com/search?q=site%3Astackoverflow.com+codeigniter+remove+index.php, other answers in this question, etc. to learn how to remove index.php from the url. The rest of this answer will assume you have that part figured out (no index.php in url).

so:

class Tutorials extends CI_Controller{

    function index(){
        //view all tutorials
    }

    function view($tutorial_identifier){
        //view single tutorial based on $tutorial_identifier
        //which can be either an id or a name
    }
}

would get you url's like

http://www.example.com/tutorials/view/5 

to view a single tutorial, and

http://www.example.com/tutorials/

to view all tutorials.

IMPORTANT READING: routes

If you want the url to look more like

http://www.example.com/tutorials/5 

for tutorial # 5, you can use a route like

$route['tutorials/(:num)'] = "tutorials/view/$1"; 

if you want it to look more like

http://example.com/tutorials/getting-started

you can add a route like

$route['tutorials/(:any)'] = "tutorials/view/$1";

and change the logic in the view function of your controller to look up the tutorial by the name rather than by the id.

Community
  • 1
  • 1
stormdrain
  • 7,915
  • 4
  • 37
  • 76
  • But i fail in first step that is remove index.php in url. the first i try to remove index.php from url but it's not working. my struction look like `http://s11.postimg.org/pijy1qpf7/Capture.jpg` And in config.php in `application\config\` i do $config['index_page'] = '';. But not working ? – DeLe Sep 07 '13 at 01:48
  • You need to use .htaccess as described in the links I posted and as posted IN OTHER ANSWERS IN THIS POST. Please do your research. Don't be lazy. – stormdrain Sep 07 '13 at 02:03