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

Saving log #25

Closed daljeet-singh closed 11 years ago

daljeet-singh commented 11 years ago

How to enable writing log to my DB?

raultm commented 10 years ago

Did you solve this issue? I can't find out the way!

raultm commented 10 years ago

Ok, I got it.

kvz commented 10 years ago

What did you do to fix it?

raultm commented 10 years ago

Ok, I should write the steps before.

First of all, thanks for share your work @kvz .

  1. I noticed that there are some callbacks in RestComponent. Doing some debug I checked out the callback cbRestlogFilter was returning null just before save.
  2. I look for the callback, by default is referenced to restlogFilter 'cbRestlogFilter' => 'restlogFilter',
  3. How callbacks are called? From the Controller using the call method `public function call ($name, $arguments) {`
  4. So we need to implement the restlofFilterin our Controller
public function restlogFilter ($Rest, $log) {
    if (Configure::read('App.api.log') === true) {
        // You could also do last minute changes to the data being logged
        return $log;
    }
    // Or return false to prevent logging alltogether
    return false;
}

I think there's a lack of documentation in this section in the README, but it's not difficult to get the solution following the code.

kvz commented 10 years ago

Thank you! I don't actively maintain this plugin but if you want to submit a documentation update PR I'm sure I can merge it

daljeet-singh commented 10 years ago

We can use this in simple way

public $components = array( 'Rest.Rest' => array(
            'catchredir' => true,
            'log' => array(
                'model' => 'Rest.RestLog',
                'pretty' => true,
            ),
            'actions' => array(
                'index' => array(
                    'extract' => array( 'orders' ),
                ),
                'view' => array(
                    'extract' => array( 'orderDetail' ),
                ),
                'add' => array(
                    'extract' => array( 'message' ),
                ),
            ),
        ),
    );

And in AppController

public function restlogFilter ($Rest, $log) {
        return $log;
    }

And in Plugin's Modal just define extra db config

public $useDbConfig = 'mongo';