Skip to content

Multipart listener for CakePHP integrated with Crud JSON API plugin.

Notifications You must be signed in to change notification settings

oskar1233/crud-multipart-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MultipartJsonApiListener plugin for CakePHP

Basically, the library utilized CakePHP's events mechanism and custom listener for multipart/form-data content type.

To handle file and JSON+API payload at once, you'll need to pass two elements in the multipart request:

  • file - with name file,
  • json+api payload - with name entity.

More docs soon.

Example usage

In Controller#initialize method:

$this->loadComponent('Crud.Crud', [
    'actions' => [
        'Crud.Index',
        'Crud.View',
        'Crud.Add',
        'Crud.Edit',
        'Crud.Delete'
    ],
    'listeners' => [
        'MultipartJsonApiListener.Multipart',
        'CrudJsonApi.Pagination',
        'Crud.Search'
    ]
]);

In controller:

public function implementedEvents() {
    return [
        'fileUploaded' => 'handleUpload'
    ];
}

public function handleUpload(Event $event) {
    $file = $event->getData();
    $addFields = [
        'url' => 'some'
    ];
    $event->subject->eventManager()->dispatch(new Event('fileProcessed', $this, $addFields));
}

About

Multipart listener for CakePHP integrated with Crud JSON API plugin.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages