0

I am creating rest api using codeigniter and want to use function but after hit "http://localhost/codeigniter-rest-api-master/api/testing" showing me error "404 page not found".Where i am wrong ?

here is my "application/config/routes.php"

   $route['api'] = 'api/users/';
    //api/users
    $route['api/users'] = 'api/testing/testing/';
    $route['api/users/format/json'] = 'api/testing/testing/format/json';
    $route['api/users/format/xml'] = 'api/testing/testing/format/xml';
    $route['api/users/format/html'] = 'api/testing/testing/format/html';
    $route['api/users/format/csv'] = 'api/testing/users/format/csv';
    $route['api/users.json'] = 'api/testing/testing.json';
    $route['api/users.xml'] = 'api/testing/testing.xml';
    $route['api/users.html'] = 'api/testing/testing.html';
    $route['api/users.csv'] = 'api/testing/testing.csv';

here is my "application/controller/api/Users.php"

public function testing()
{
    echo "hello world";

}
amit
  • 1
  • 4

1 Answers1

0

You don't have a api/testing route. Use something like this

$route['api/testing'] = 'api/users/testing/';

The route is folder/controller_class/function. I think you should read the guide. This Answer would be helpful too.

Abhishek
  • 372
  • 1
  • 6
  • 13
  • not working ( in controller my controller there is folder name "api" , where users controller exist – amit Dec 01 '18 at 06:54
  • How are you declaring routes? – Abhishek Dec 01 '18 at 07:08
  • with following code now i am getting correct result $route["Users"]["GET"] = "api/index_get"; – amit Dec 01 '18 at 07:23
  • Good for you. I am currently trying to make rest api using CI too ;-) – Abhishek Dec 01 '18 at 07:27
  • i am using post method but not working , may i know why ? $route["Users"]["POST"] = "api/index_get"; – amit Dec 01 '18 at 07:33
  • @amit is 'api' a controller file? without the code I can't help much. But check this [answer](https://stackoverflow.com/questions/14710509/codeigniter-routing-and-rest-server) – Abhishek Dec 01 '18 at 07:38
  • api is my foldername in controller and in api folder there is Users controller – amit Dec 01 '18 at 07:44