Codeigniter URI Class how can i use – hyphen instead _ underscore? Codeigniter URI Class how can i use – hyphen instead _ underscore? codeigniter codeigniter

Codeigniter URI Class how can i use – hyphen instead _ underscore?


if you're using Codeigniter 3 open your config/routes.php

$route['translate_uri_dashes'] = TRUE;


Yes you can.

Normally CI produce url like this base_url/Controller_name/Method_name.

As you know controller name and method name cannot contain '-'(hyphen) so you cannot change their name.

What can you do is use router to show the correct controller with corresponding url.

Like you can write this code at your config/routes.php

$route['get-artist-discography/artist-name'] ='get_artist_discography/artist_name';

This will execute your get_artist_discography controller and artist_name method if your link is http://localhost:8888/ci/index.php/get-artist-discography/artist-name

You can learn more about URI Routing at CI docs