philiplb / CRUDlex

CRUDlex is an easy to use CRUD generator for Symfony 4 and Silex 2 which is great for auto generated admin pages
https://philiplb.de/crudlex/
MIT License
109 stars 23 forks source link

pushEvent after create + file upload #44

Closed germain-italic closed 8 years ago

germain-italic commented 8 years ago

Hi, when working with pushEvents I am trying to process a file automatically after upload.

I'm using an after create event, but it seems that it is fired before the file is actually uploaded (not present on the disk).

The following code sample always returns $file = false:

$xls2json = function(CRUDlex\CRUDEntity $entity) {

    $filename   = $entity->get('filename');

    $fileid     = $entity->get('id');
    $path       = dirname(__DIR__).'/www/uploads/imports'; // any way to get it from the .yml?
    $filepath   = $path.'/'.$fileid.'/'.$filename;

    $file       = file_exists($filepath) ? $filepath : false;

    var_dump($file);
    exit();
    return true;
};
$app['crud']->getData('imports')->pushEvent('after', 'create', $xls2json);
germain-italic commented 8 years ago

Not exactly related to issue #45. Is it normal that the file is being uploaded after the after create event?

philiplb commented 8 years ago

This is due to the nature of this current after-events being triggered as soon as the object is saved to the database. Afterwards, the files are handled. I might just introduce a set of new before/after-events for files.

germain-italic commented 8 years ago

Got it working! Thanks :+1: