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

Broken events #43

Closed germain-italic closed 8 years ago

germain-italic commented 8 years ago

Well, broken or I don't know how to use them. Test from a fresh project sample both in v0.9.9 and v0.9.x-dev, I added this on line 38:

New syntax:

$app['crud']->getData('library')->pushEvent('before', 'create', function(Entity $entity) {
    // Do something with the entity which is about to be saved.
    return true;
});

Generates:

Catchable fatal error: Argument 1 passed to {closure}() must be an instance of Entity, instance of CRUDlex\Entity given, called in /CRUDlexSample-master/vendor/philiplb/crudlex/src/CRUDlex/Data.php on line 104 and defined in //CRUDlexSample-master/web/index.php on line 39

Old syntax:

$app['crud']->getData('library')->pushEvent('before', 'create', function(CRUDEntity $entity) {
    // Do something with the entity which is about to be saved.
    return true;
});

Generates:

Catchable fatal error: Argument 1 passed to {closure}() must be an instance of CRUDEntity, instance of CRUDlex\Entity given, called in //CRUDlexSample-master/vendor/philiplb/crudlex/src/CRUDlex/Data.php on line 104 and defined in /CRUDlexSample-master/web/index.php on line 40
philiplb commented 8 years ago

Have you added the according use statement?

// <= 0.9.9
use CRUDlex\CRUDEntity;
// > 0.9.9
use CRUDlex\Entity;

Or include the namespace CRUDlex within the closure:

$app['crud']->getData('library')->pushEvent('before', 'create', function(CRUDlex\Entity $entity) {
    // Do something with the entity which is about to be saved.
    return true;
});
philiplb commented 8 years ago

I extended the documentation a bit here and included the namespace: http://philiplb.github.io/CRUDlex/docs/html/0.9.10/manual/events.html

philiplb commented 8 years ago

@ashorlivs Just reopen this issue if that doesn't solve your problem.

germain-italic commented 8 years ago

Thank you, that actually solved the problem!