Codeigniter RESTful API - {“status”:false,“error”:“Unknown method.”}
I've managed to setup the RESTful API in my Codeigniter Application. Now I want to get some data from my MySQL database, so in my Codeigniter models folder I have created a model called category_model.php:
<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
Then in the Codeigniter controller-folder I created a category.php file:
<?php
include(APPPATH.'libraries/REST_Controller.php');
class Category extends REST_Controller {
function __construct()
{
parent::__construct();
$this->load->model('category_model');
}
function category_get()
{
$data = $this->category_model->get_all_categories();
$this->response($data);
}
}
?>
Now, when I enter http://localhost/myproejcts/ci/index.php/category/category
- I get the error {"status":false,"error":"Unknown method."}
??
what is the issue?
[UPDATE] = I get the same error when setting function index_post()
php mysql codeigniter rest
|
show 3 more comments
I've managed to setup the RESTful API in my Codeigniter Application. Now I want to get some data from my MySQL database, so in my Codeigniter models folder I have created a model called category_model.php:
<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
Then in the Codeigniter controller-folder I created a category.php file:
<?php
include(APPPATH.'libraries/REST_Controller.php');
class Category extends REST_Controller {
function __construct()
{
parent::__construct();
$this->load->model('category_model');
}
function category_get()
{
$data = $this->category_model->get_all_categories();
$this->response($data);
}
}
?>
Now, when I enter http://localhost/myproejcts/ci/index.php/category/category
- I get the error {"status":false,"error":"Unknown method."}
??
what is the issue?
[UPDATE] = I get the same error when setting function index_post()
php mysql codeigniter rest
It's saying the method (category) cannot be found. Are you sure the server request method is get? You can check by doing $this->input->server('REQUEST_METHOD')
– foxmulder
Jan 13 '14 at 13:52
Shouldn't it beindex_get()
instead ofcategory_get()
? Based on github.com/philsturgeon/…
– André Dion
Jan 13 '14 at 13:52
@AndréDionindex_get()
doesnt work.. i get more serious errors I dont get...
– SHT
Jan 13 '14 at 14:13
@foxmulder The check doesnt give me anything... unless i checked the wrong place? I checked inside category_get() function...
– SHT
Jan 13 '14 at 14:14
Anyone? I'm running out of ideas?
– SHT
Jan 13 '14 at 16:40
|
show 3 more comments
I've managed to setup the RESTful API in my Codeigniter Application. Now I want to get some data from my MySQL database, so in my Codeigniter models folder I have created a model called category_model.php:
<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
Then in the Codeigniter controller-folder I created a category.php file:
<?php
include(APPPATH.'libraries/REST_Controller.php');
class Category extends REST_Controller {
function __construct()
{
parent::__construct();
$this->load->model('category_model');
}
function category_get()
{
$data = $this->category_model->get_all_categories();
$this->response($data);
}
}
?>
Now, when I enter http://localhost/myproejcts/ci/index.php/category/category
- I get the error {"status":false,"error":"Unknown method."}
??
what is the issue?
[UPDATE] = I get the same error when setting function index_post()
php mysql codeigniter rest
I've managed to setup the RESTful API in my Codeigniter Application. Now I want to get some data from my MySQL database, so in my Codeigniter models folder I have created a model called category_model.php:
<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
Then in the Codeigniter controller-folder I created a category.php file:
<?php
include(APPPATH.'libraries/REST_Controller.php');
class Category extends REST_Controller {
function __construct()
{
parent::__construct();
$this->load->model('category_model');
}
function category_get()
{
$data = $this->category_model->get_all_categories();
$this->response($data);
}
}
?>
Now, when I enter http://localhost/myproejcts/ci/index.php/category/category
- I get the error {"status":false,"error":"Unknown method."}
??
what is the issue?
[UPDATE] = I get the same error when setting function index_post()
php mysql codeigniter rest
php mysql codeigniter rest
edited Jan 13 '14 at 14:32
SHT
asked Jan 13 '14 at 13:44
SHTSHT
38511136
38511136
It's saying the method (category) cannot be found. Are you sure the server request method is get? You can check by doing $this->input->server('REQUEST_METHOD')
– foxmulder
Jan 13 '14 at 13:52
Shouldn't it beindex_get()
instead ofcategory_get()
? Based on github.com/philsturgeon/…
– André Dion
Jan 13 '14 at 13:52
@AndréDionindex_get()
doesnt work.. i get more serious errors I dont get...
– SHT
Jan 13 '14 at 14:13
@foxmulder The check doesnt give me anything... unless i checked the wrong place? I checked inside category_get() function...
– SHT
Jan 13 '14 at 14:14
Anyone? I'm running out of ideas?
– SHT
Jan 13 '14 at 16:40
|
show 3 more comments
It's saying the method (category) cannot be found. Are you sure the server request method is get? You can check by doing $this->input->server('REQUEST_METHOD')
– foxmulder
Jan 13 '14 at 13:52
Shouldn't it beindex_get()
instead ofcategory_get()
? Based on github.com/philsturgeon/…
– André Dion
Jan 13 '14 at 13:52
@AndréDionindex_get()
doesnt work.. i get more serious errors I dont get...
– SHT
Jan 13 '14 at 14:13
@foxmulder The check doesnt give me anything... unless i checked the wrong place? I checked inside category_get() function...
– SHT
Jan 13 '14 at 14:14
Anyone? I'm running out of ideas?
– SHT
Jan 13 '14 at 16:40
It's saying the method (category) cannot be found. Are you sure the server request method is get? You can check by doing $this->input->server('REQUEST_METHOD')
– foxmulder
Jan 13 '14 at 13:52
It's saying the method (category) cannot be found. Are you sure the server request method is get? You can check by doing $this->input->server('REQUEST_METHOD')
– foxmulder
Jan 13 '14 at 13:52
Shouldn't it be
index_get()
instead of category_get()
? Based on github.com/philsturgeon/…– André Dion
Jan 13 '14 at 13:52
Shouldn't it be
index_get()
instead of category_get()
? Based on github.com/philsturgeon/…– André Dion
Jan 13 '14 at 13:52
@AndréDion
index_get()
doesnt work.. i get more serious errors I dont get...– SHT
Jan 13 '14 at 14:13
@AndréDion
index_get()
doesnt work.. i get more serious errors I dont get...– SHT
Jan 13 '14 at 14:13
@foxmulder The check doesnt give me anything... unless i checked the wrong place? I checked inside category_get() function...
– SHT
Jan 13 '14 at 14:14
@foxmulder The check doesnt give me anything... unless i checked the wrong place? I checked inside category_get() function...
– SHT
Jan 13 '14 at 14:14
Anyone? I'm running out of ideas?
– SHT
Jan 13 '14 at 16:40
Anyone? I'm running out of ideas?
– SHT
Jan 13 '14 at 16:40
|
show 3 more comments
5 Answers
5
active
oldest
votes
Depends of your HTTP request to your controller "Category" it will call related method:
public function index_get()
{
echo "GET_request";
}
public function index_post()
{
echo "POST_request";
}
public function index_put()
{
echo "PUT_request";
}
public function index_patch()
{
echo "PATCH_request";
}
public function index_delete()
{
echo "DELETE_request";
}
So, rename your method to 'index_get'
add a comment |
I think your problem is the name of controller is the same with the name of method try to make a test:
if the name of your controller is:
class Test extends CI_Controller{
//your method name is different from the name of controller class
public function testget_get(){
echo $this->response(array('test'=> 'test'), 200);
}
}
I have experienced this problem on hmvc structure.
so for example the name of my controller iscontrollername
all i need to do to my functions iscontrollername_get
controllername_post
etc?
– kev_m
Apr 22 '16 at 4:51
no must be different, if your controller is called [Test] your method name should be different from your controller name excluding postfix [_get, _post].. example [name_get]. So $this->test->name_get() and not $this->test->test_get().
– onalbi
Apr 22 '16 at 10:12
okay. thankyou so much!
– kev_m
Apr 22 '16 at 11:11
add a comment |
while calling the method don't use _get,_post ..
say for example
you have a method users_get
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Student extends REST_Controller {
function __construct() {
// Construct the parent class
parent::__construct();
}
public function users_get() {
$this->response("my first api");
}
}
?>
let us call this method => "your base url"/student/users
Please provide a description for your answer.
– Rohan Khude
Aug 16 '16 at 6:25
add a comment |
mention the details you want to fetch from database and enter the correct name in the database file located in /restapi/application/config/database file and run the code.
this error occurs due to the incorrect database name
**<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('name, email');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>**
add a comment |
Please change your class name to start with capital letter and make sure your file name also starts with capital letter
<?php
Class Category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21092792%2fcodeigniter-restful-api-statusfalse-errorunknown-method%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Depends of your HTTP request to your controller "Category" it will call related method:
public function index_get()
{
echo "GET_request";
}
public function index_post()
{
echo "POST_request";
}
public function index_put()
{
echo "PUT_request";
}
public function index_patch()
{
echo "PATCH_request";
}
public function index_delete()
{
echo "DELETE_request";
}
So, rename your method to 'index_get'
add a comment |
Depends of your HTTP request to your controller "Category" it will call related method:
public function index_get()
{
echo "GET_request";
}
public function index_post()
{
echo "POST_request";
}
public function index_put()
{
echo "PUT_request";
}
public function index_patch()
{
echo "PATCH_request";
}
public function index_delete()
{
echo "DELETE_request";
}
So, rename your method to 'index_get'
add a comment |
Depends of your HTTP request to your controller "Category" it will call related method:
public function index_get()
{
echo "GET_request";
}
public function index_post()
{
echo "POST_request";
}
public function index_put()
{
echo "PUT_request";
}
public function index_patch()
{
echo "PATCH_request";
}
public function index_delete()
{
echo "DELETE_request";
}
So, rename your method to 'index_get'
Depends of your HTTP request to your controller "Category" it will call related method:
public function index_get()
{
echo "GET_request";
}
public function index_post()
{
echo "POST_request";
}
public function index_put()
{
echo "PUT_request";
}
public function index_patch()
{
echo "PATCH_request";
}
public function index_delete()
{
echo "DELETE_request";
}
So, rename your method to 'index_get'
answered Jul 18 '16 at 14:26
Alex DomAlex Dom
511
511
add a comment |
add a comment |
I think your problem is the name of controller is the same with the name of method try to make a test:
if the name of your controller is:
class Test extends CI_Controller{
//your method name is different from the name of controller class
public function testget_get(){
echo $this->response(array('test'=> 'test'), 200);
}
}
I have experienced this problem on hmvc structure.
so for example the name of my controller iscontrollername
all i need to do to my functions iscontrollername_get
controllername_post
etc?
– kev_m
Apr 22 '16 at 4:51
no must be different, if your controller is called [Test] your method name should be different from your controller name excluding postfix [_get, _post].. example [name_get]. So $this->test->name_get() and not $this->test->test_get().
– onalbi
Apr 22 '16 at 10:12
okay. thankyou so much!
– kev_m
Apr 22 '16 at 11:11
add a comment |
I think your problem is the name of controller is the same with the name of method try to make a test:
if the name of your controller is:
class Test extends CI_Controller{
//your method name is different from the name of controller class
public function testget_get(){
echo $this->response(array('test'=> 'test'), 200);
}
}
I have experienced this problem on hmvc structure.
so for example the name of my controller iscontrollername
all i need to do to my functions iscontrollername_get
controllername_post
etc?
– kev_m
Apr 22 '16 at 4:51
no must be different, if your controller is called [Test] your method name should be different from your controller name excluding postfix [_get, _post].. example [name_get]. So $this->test->name_get() and not $this->test->test_get().
– onalbi
Apr 22 '16 at 10:12
okay. thankyou so much!
– kev_m
Apr 22 '16 at 11:11
add a comment |
I think your problem is the name of controller is the same with the name of method try to make a test:
if the name of your controller is:
class Test extends CI_Controller{
//your method name is different from the name of controller class
public function testget_get(){
echo $this->response(array('test'=> 'test'), 200);
}
}
I have experienced this problem on hmvc structure.
I think your problem is the name of controller is the same with the name of method try to make a test:
if the name of your controller is:
class Test extends CI_Controller{
//your method name is different from the name of controller class
public function testget_get(){
echo $this->response(array('test'=> 'test'), 200);
}
}
I have experienced this problem on hmvc structure.
answered Jan 28 '14 at 9:09


onalbionalbi
1,1381730
1,1381730
so for example the name of my controller iscontrollername
all i need to do to my functions iscontrollername_get
controllername_post
etc?
– kev_m
Apr 22 '16 at 4:51
no must be different, if your controller is called [Test] your method name should be different from your controller name excluding postfix [_get, _post].. example [name_get]. So $this->test->name_get() and not $this->test->test_get().
– onalbi
Apr 22 '16 at 10:12
okay. thankyou so much!
– kev_m
Apr 22 '16 at 11:11
add a comment |
so for example the name of my controller iscontrollername
all i need to do to my functions iscontrollername_get
controllername_post
etc?
– kev_m
Apr 22 '16 at 4:51
no must be different, if your controller is called [Test] your method name should be different from your controller name excluding postfix [_get, _post].. example [name_get]. So $this->test->name_get() and not $this->test->test_get().
– onalbi
Apr 22 '16 at 10:12
okay. thankyou so much!
– kev_m
Apr 22 '16 at 11:11
so for example the name of my controller is
controllername
all i need to do to my functions is controllername_get
controllername_post
etc?– kev_m
Apr 22 '16 at 4:51
so for example the name of my controller is
controllername
all i need to do to my functions is controllername_get
controllername_post
etc?– kev_m
Apr 22 '16 at 4:51
no must be different, if your controller is called [Test] your method name should be different from your controller name excluding postfix [_get, _post].. example [name_get]. So $this->test->name_get() and not $this->test->test_get().
– onalbi
Apr 22 '16 at 10:12
no must be different, if your controller is called [Test] your method name should be different from your controller name excluding postfix [_get, _post].. example [name_get]. So $this->test->name_get() and not $this->test->test_get().
– onalbi
Apr 22 '16 at 10:12
okay. thankyou so much!
– kev_m
Apr 22 '16 at 11:11
okay. thankyou so much!
– kev_m
Apr 22 '16 at 11:11
add a comment |
while calling the method don't use _get,_post ..
say for example
you have a method users_get
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Student extends REST_Controller {
function __construct() {
// Construct the parent class
parent::__construct();
}
public function users_get() {
$this->response("my first api");
}
}
?>
let us call this method => "your base url"/student/users
Please provide a description for your answer.
– Rohan Khude
Aug 16 '16 at 6:25
add a comment |
while calling the method don't use _get,_post ..
say for example
you have a method users_get
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Student extends REST_Controller {
function __construct() {
// Construct the parent class
parent::__construct();
}
public function users_get() {
$this->response("my first api");
}
}
?>
let us call this method => "your base url"/student/users
Please provide a description for your answer.
– Rohan Khude
Aug 16 '16 at 6:25
add a comment |
while calling the method don't use _get,_post ..
say for example
you have a method users_get
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Student extends REST_Controller {
function __construct() {
// Construct the parent class
parent::__construct();
}
public function users_get() {
$this->response("my first api");
}
}
?>
let us call this method => "your base url"/student/users
while calling the method don't use _get,_post ..
say for example
you have a method users_get
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Student extends REST_Controller {
function __construct() {
// Construct the parent class
parent::__construct();
}
public function users_get() {
$this->response("my first api");
}
}
?>
let us call this method => "your base url"/student/users
edited Aug 16 '16 at 7:27


Martin Gottweis
2,400825
2,400825
answered Aug 16 '16 at 6:22
Virendra PawarVirendra Pawar
111
111
Please provide a description for your answer.
– Rohan Khude
Aug 16 '16 at 6:25
add a comment |
Please provide a description for your answer.
– Rohan Khude
Aug 16 '16 at 6:25
Please provide a description for your answer.
– Rohan Khude
Aug 16 '16 at 6:25
Please provide a description for your answer.
– Rohan Khude
Aug 16 '16 at 6:25
add a comment |
mention the details you want to fetch from database and enter the correct name in the database file located in /restapi/application/config/database file and run the code.
this error occurs due to the incorrect database name
**<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('name, email');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>**
add a comment |
mention the details you want to fetch from database and enter the correct name in the database file located in /restapi/application/config/database file and run the code.
this error occurs due to the incorrect database name
**<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('name, email');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>**
add a comment |
mention the details you want to fetch from database and enter the correct name in the database file located in /restapi/application/config/database file and run the code.
this error occurs due to the incorrect database name
**<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('name, email');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>**
mention the details you want to fetch from database and enter the correct name in the database file located in /restapi/application/config/database file and run the code.
this error occurs due to the incorrect database name
**<?php
Class category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('name, email');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>**
answered Jan 9 '18 at 6:15
user9116204
add a comment |
add a comment |
Please change your class name to start with capital letter and make sure your file name also starts with capital letter
<?php
Class Category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
add a comment |
Please change your class name to start with capital letter and make sure your file name also starts with capital letter
<?php
Class Category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
add a comment |
Please change your class name to start with capital letter and make sure your file name also starts with capital letter
<?php
Class Category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
Please change your class name to start with capital letter and make sure your file name also starts with capital letter
<?php
Class Category_model extends CI_Model {
var $table_name = 'category';
function get_all_categories()
{
$this->db->select('*');
$this->db->from($this->table_name);
return $this->db->get();
}
}
?>
answered Jan 2 at 11:48


K Jagannath ReddyK Jagannath Reddy
516
516
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21092792%2fcodeigniter-restful-api-statusfalse-errorunknown-method%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's saying the method (category) cannot be found. Are you sure the server request method is get? You can check by doing $this->input->server('REQUEST_METHOD')
– foxmulder
Jan 13 '14 at 13:52
Shouldn't it be
index_get()
instead ofcategory_get()
? Based on github.com/philsturgeon/…– André Dion
Jan 13 '14 at 13:52
@AndréDion
index_get()
doesnt work.. i get more serious errors I dont get...– SHT
Jan 13 '14 at 14:13
@foxmulder The check doesnt give me anything... unless i checked the wrong place? I checked inside category_get() function...
– SHT
Jan 13 '14 at 14:14
Anyone? I'm running out of ideas?
– SHT
Jan 13 '14 at 16:40