Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'Restserver\Libraries\REST_Controller' #912

Closed
S-Masoud-Emamian opened this issue Mar 24, 2018 · 15 comments
Closed

Class 'Restserver\Libraries\REST_Controller' #912

S-Masoud-Emamian opened this issue Mar 24, 2018 · 15 comments

Comments

@S-Masoud-Emamian
Copy link

I want to use Rest api,I'm using chriskacerguis/codeigniter-restserver:

"require": {
	"php": ">=5.3.7",
	"chriskacerguis/codeigniter-restserver": "^3.0"
},

I got this error:

   Fatal error: Class 'Restserver\Libraries\REST_Controller' not found 

my class:

<?php
  namespace Restserver\Libraries;
  use Restserver\Libraries\REST_Controller;

   class Api extends REST_Controller {

     public function __construct(){
	     parent::__construct();
}
	


public function user_get()
{

    $users = [
        'id' => 100, // Automatically generated by the model
        'name' => $this->post('name'),
        'email' => $this->post('email'),
        'message' => 'Added a resource'
    ];

    $this->response($users, REST_Controller::HTTP_OK);
}

}

+controllers
   +Api
      Api.php
@fabianblum
Copy link
Contributor

Remove the use. This version of the rest server don't have a namespace.

Your class should look like

<?php
  namespace Restserver\Libraries;

   class Api extends \REST_Controller {

     public function __construct(){
	     parent::__construct();
}
... 

@S-Masoud-Emamian
Copy link
Author

I got this error output:

 Fatal error: Class 'REST_Controller' not found in C:\xampp\htdocs\shadyab\application\controllers\Api\Api.php on line 3

my class:

<?php
namespace Restserver\Libraries;
class Api extends \REST_Controller {
	
	public function __construct(){
		parent::__construct();
	}
		


	public function user_get()
    {

        $users = [
            'id' => 100, // Automatically generated by the model
            'name' => $this->post('name'),
            'email' => $this->post('email'),
            'message' => 'Added a resource'
        ];

        $this->response($users, REST_Controller::HTTP_OK);
    }
		
	
}

@luckydonald
Copy link
Contributor

luckydonald commented Apr 3, 2018

Just remove use Restserver\Libraries\REST_Controller, and probably without namespace.
This seem to have happened somewhere between 3.0.0 and 3.0.3.

@anuragyadav8949
Copy link

@Hanisch-IT
Hey i have used the same thing(namespace) but it shows the error
" Class 'Restserver\Libraries\CI_Controller' not found in"

Could plz tell me about what is Restserver is
my lib struct is
+app
+libraries
->Rest_Controller.php

@fabianblum
Copy link
Contributor

Hi @anuragyadav8949,

how did you include the Codeigniter_Restserver? Did you copy&paste the files to your library folder or did you install it via composer?

@anuragyadav8949
Copy link

@Hanisch-IT
Copy Paste two files from the github
"format.php , Rext_controller.php"

Thanks for response :)

@anuragyadav8949
Copy link

Hey
I resolved the error
by adding line in Rest_controller => "use CI_Controller;"
in my controller => use Restserver\Libraries\REST_Controller;

Now Again error occured is => "Class 'Restserver\Libraries\Format' not found in libraries\REST_controller.php "

U can direct message me on my mail
anurag.yadav8949@gmail.com

Waiting for reply:)

@etranger-park
Copy link

I have same problems and solve it!
add
require APPPATH . 'libraries/Format.php';
in REST_Controller.php

@atukilham
Copy link

i got another error after upgrade:

An Error Was Encountered
Non-existent class: Format

I try add use Restserver\Libraries\Format; in REST_Controller.php, like this :

namespace Restserver\Libraries;
use Exception;
use stdClass;
use Restserver\Libraries\Format;

But still error, please help.

@adhimasprayogie
Copy link

adhimasprayogie commented Jul 17, 2018

Help me please!

I got this error

Fatal error: Class 'REST_Controller' not found in C:\xampp\htdocs\rest_server\application\controllers\Itp.php on line 5

and this is my code

code1
code2
code3
code4
code5

@farukgaric
Copy link

Just remove \ "backslash" before REST_Controller

@azmiadhani
Copy link

I have same problems and solve it!
add
require APPPATH . 'libraries/Format.php';
in REST_Controller.php

Thanks a alot

@sidiqfatkhul9
Copy link

An uncaught Exception was encountered
Type: Error

Message: Class 'Restserver\Libraries\Format' not found

Filename: C:\xampp\htdocs\pegawai\rest_ci\application\libraries\REST_Controller.php

Line Number: 853

Backtrace:

File: C:\xampp\htdocs\pegawai\rest_ci\application\libraries\REST_Controller.php
Line: 737
Function: response

File: C:\xampp\htdocs\pegawai\rest_ci\index.php
Line: 315
Function: require_once

@didiwahyudi12
Copy link

didiwahyudi12 commented Oct 16, 2019

got this error:
Fatal error: Class 'REST_Controller' not found in D:\XAMPP\htdocs\restCI\application\controllers\TestApi.php on line 6

my class:

<?php

  namespace Restserver\Libraries;
  

   class TestApi extends \REST_Controller {

     public function __construct(){
	     parent::__construct();
	 }

	public function index_get(){
	
	    $response['status']=200;
	    $response['error']=false;
	    $response['message']='Hai from response';
	    
	    $this->response($response);
	}

	public function user_get(){
	    $response['status']=200;
	    $response['error']=false;
	    $response['user']['username']='erthru';
	    $response['user']['email']='ersaka96@gmail.com';
	    $response['user']['detail']['full_name']='Suprianto D';
	    $response['user']['detail']['position']='Developer';
	    $response['user']['detail']['specialize']='Android,IOS,WEB,Desktop';
	    $this->response($response);
	}
	
}
?>

@dikaheni
Copy link

dikaheni commented May 4, 2020

how do i redirect resfull api I want after input_post () page will be redirected

 public function loginsi_post(){
    $username = $this->post('username');
    $password = $this->post('password');
    $data = [];
    $data['username'] = $username;
    $data['password'] = $password;
    if ($this->model_app->insert('jajal', $data) > 0) {
        $this->response([
            'message' => 'data berhasil disimpan',
            'data'    => $data
        ], REST_Controller::HTTP_CREATED);
    }else{
        $this->response([
            'message' => 'data gagal disimpan'
        ], REST_Controller::HTTP_CREATED);
    }
redirect('main/home'); -> is not working
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests