chriskacerguis / codeigniter-restserver

A fully RESTful server implementation for CodeIgniter using one library, one config file and one controller.
MIT License
4.89k stars 2.86k forks source link

Conflict when using together with Rest-Client library #69

Closed luoihoc closed 12 years ago

luoihoc commented 12 years ago

I installed rest-client library using sparks command line. When i try to load the rest-client library in a Rest Controller, i have the following error

PHP Fatal error:  Cannot access protected property Example::$rest in /home/tran/public_html/peacemoon/system/core/Loader.php on line 1095

This is the code in my Rest Controller

public function test_get() {
    $this->load->spark('restclient/2.0.0');

    // Load the library
    $this->load->library('rest');

    $this->response('hello', 200);
}
luoihoc commented 12 years ago

I was able to make my code to run by change all the variables in REST_Controller.php from "protected" to "private"

private $rest_format = NULL; // Set this in a controller to use a default format
private $methods = array(); // contains a list of method properties such as limit, log and level
private $request = NULL; // Stores accept, language, body, headers, etc
private $response = NULL; // What is gonna happen in output?
private $rest = NULL; // Stores DB, keys, key level, etc
private $_get_args = array();
private $_post_args = array();
private $_put_args = array();
private $_delete_args = array();
private $_args = array();
private $_allow = TRUE;

// List all supported methods, the first will be the default format
private $_supported_formats = array(
    'xml' => 'application/xml',
    'rawxml' => 'application/xml',
    'json' => 'application/json',
    'jsonp' => 'application/javascript',
    'serialized' => 'application/vnd.php.serialized',
    'php' => 'text/plain',
    'html' => 'text/html',
    'csv' => 'application/csv'
);

This may relate to this bug report: https://github.com/philsturgeon/codeigniter-template/issues/22

sledmonkey commented 12 years ago

Thanks luoihoc, that solved my problem!

philsturgeon commented 12 years ago

Can somebody send in a pull request?

StevenBullen commented 11 years ago

Hey Phil This issue has been closed but the changes were never made, was this fixed elsewhere?

philsturgeon commented 11 years ago

If its still broken please send in a pull request that fixes it.

StevenBullen commented 11 years ago

I will take a look at it either this evening or tomorrow and send along a pull request.

philsturgeon commented 11 years ago

Thanks buddy.

Phil Sturgeon

On Wednesday, 23 January 2013 at 07:32, Steven Bullen wrote:

Hey Phil This issue has been closed but the changes were never made, was this fixed elsewhere?

— Reply to this email directly or view it on GitHub (https://github.com/philsturgeon/codeigniter-restserver/issues/69#issuecomment-12593506).

rolandinsh commented 11 years ago

worked for me making only $rest private;

ngplus commented 9 years ago

hey, the final fixed is still not pulled to the latest Rest Server library ?

ivantcholakov commented 9 years ago

REST_Controller is to be extended, I prefer its properties to be protected, not private.

softwarespot commented 9 years ago

Agreed

ngplus commented 9 years ago

then what should be the correct approach if we want to use the same class as a Rest server and Client together ?

softwarespot commented 9 years ago

That isn't maintained by us is it?

ivantcholakov commented 9 years ago

First thoughts:

  1. The REST library to be "adopted" by this project. :-)
  2. It to be renamed as Rest_client.
  3. A test showing them working simultaneously to be prepared.
ivantcholakov commented 9 years ago

Meanwhile... $this->load->library('rest', $config, 'rest_client');

softwarespot commented 9 years ago

I will confess I have never used Rest_client nor probably will I ever. But I am game if everyone else is =)

ivantcholakov commented 9 years ago

In my demo with the Rest Client library I did not extend the controller class from REST_Controller, but at least the following commit shows how can the name conflict be resolved: https://github.com/ivantcholakov/starter-public-edition-3/commit/0030a94d3c20e853c3baf823312eee9ae4db9389

ivantcholakov commented 9 years ago

Also, the REST client library should be renamed, because the configuration file of the REST_Controller is named as rest.php. This is a second name conflict.

With a renamed client library, if we want to define some configuration options, its configuration file will be named as rest_client.php.

ivantcholakov commented 9 years ago

@chriskacerguis

What do you think about putting the REST client library an the Curl library in this project? I can make the initial commits and put some tests. Then (@softwarespot) conversion to PHP 5.4 follows and some polishing.

softwarespot commented 9 years ago

If I have time =)

ivantcholakov commented 9 years ago

No problem, I can cover the whole thing.

ivantcholakov commented 9 years ago

http://forum.codeigniter.com/thread-62631-post-321417.html