evan108108 / RESTFullYii

RESTFull API for your Yii application

Home Page:http://evan108108.github.com/RESTFullYii/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to filter response of PUT, POST actions.

miteshsc opened this issue · comments

Hello @evan108108 ,

Using POST & PUT method I am Adding & Updating user data. Before sending back response it fetching user relational data which I don't want. but I just want success/fail message in my response.

I have used following event to unset relational data, which is working fine as per my expectations. But removing profiles manually which doesn't make sense because query for selecting user profile is still getting executed.

$this->onRest('post.filter.req.put.resource.render', function($json) {
            $j = CJSON::decode($json);
            $j['data'] = array_map(function($user_data){
                unset($user_data['profiles']);
                return $user_data;
            }, $j['data']);
        return $j;
    });

Is there any way to solve this problem?

Why not just remove the relation in the first place?

$this->onRest('post.filter.model.with.relations', function($result)) {
   array_filter ( $result , function($relation) { return $relation != 'profiles'; } );
});

@miteshsc :> Can this issue be closed?

Thanks, It works!