kvz / cakephp-rest-plugin

Discontinued: recent cakephp versions overlap functionality, there also is @ceeram's plugin. Painless REST server Plugin for CakePHP
http://kvz.io/blog/2010/01/13/cakephp-rest-plugin-presentation/
169 stars 37 forks source link

Unable to establish class #23

Closed raghava closed 11 years ago

raghava commented 11 years ago

Whats wrong with the code. Getting 'Unable to establish class' in the response and data node shows empty instead ?

// Controller code
<?php
class RestsController extends AppController {
    // var $uses = array('User');
    public $components = array (
        'RequestHandler',
        'Rest.Rest' => array(
            'catchredir' => true,
            'actions' => array(
                'extract' => array(
                    'index' => array('users'),
                ),
            ),
            'log' => array(
                'pretty' => true,
            ),
        ),
    );

    public function beforeFilter() {
        $this->Auth->allow('*');
    }

    /**
     * Shortcut so you can check in your Controllers wether
     * REST Component is currently active.
     *
     * Use it in your ->flash() methods
     * to forward errors to REST with e.g. $this->Rest->error()
     *
     * @return boolean
     */
    protected function _isRest() {
        return !empty($this->Rest) && is_object($this->Rest) && $this->Rest->isActive();
    }

    public function index(){
        $users = array(
            array('name' => 'user-1'),
            array('name' => 'user-2'),
            array('name' => 'user-3')
        );
        $this->set(compact('users'));
    }
}
?>
// XML response
<rests_response>
<data>
<Rest/>
</data>
<meta>
<status>ok</status>
<feedback>
<item>
<message>Unable to establish class</message>
<level>warning</level>
</item>
</feedback>
<request>
<http_host>localhost</http_host>
<http_user_agent>
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
</http_user_agent>
<server_addr>::1</server_addr>
<remote_addr>::1</remote_addr>
<server_protocol>HTTP/1.1</server_protocol>
<request_method>GET</request_method>
<request_uri>/rests/index.xml</request_uri>
<request_time>1352045966</request_time>
</request>
<credentials>
<class>NULL</class>
<apikey>NULL</apikey>
<username>NULL</username>
</credentials>
<time_epoch>1352045966</time_epoch>
<time_local>Sun, 04 Nov 2012 08:19:26 -0800</time_local>
<version>0.3</version>
</meta>
</rests_response>
kvz commented 11 years ago

Ratelimiter works on class-basis so you can have different limits for e.g. Employees / Bots / Customers. Supply a class in your auth or do not use ratelimiting

raghava commented 11 years ago

Thanks, I have changed the $components to

    public $components = array (
        'RequestHandler',
        'Rest.Rest' => array(
            'catchredir' => true,
            'actions' => array(
                'extract' => array(
                    'index' => array('users'),
                ),
            ),
            'log' => array(
                'pretty' => true,
            ),
            'ratelimit' => array(
                'enable' => false
            ),
        ),
    );

"Unable to establish class" feedback is not showing up now.

But why I'm not getting the "users" values in the XML from index() action?

kvz commented 11 years ago

unable to determine by this snippet

raghava commented 11 years ago
// routes.php

    // Add an element for each controller that you want to open up
    // in the REST API
    Router::mapResources(array('rests'));

    // Add XML + JSON to your parseExtensions
    Router::parseExtensions('json', 'xml');
TeckniX commented 11 years ago

Provide also your php/cakePHP versions - so we can setup a similar case

raghava commented 11 years ago

CakePHP version is 2.2.2

Mixelito commented 11 years ago

I am facing the same problem. The data are not being built in xml.

Cake version: 2.1.0