All Events triggered are returning ''Cake\Event\Event'' rather than intended return string

8 views
Skip to first unread message

Paul West

unread,
Sep 8, 2016, 6:17:45 AM9/8/16
to QuickApps CMS

I'm having issues with my event listeners not returning strings but instead returning Cake\Event\Event thus throwing an error when I try and echo them:

Object of class Cake\Event\Event could not be converted to string

I went back to your docs and followed your hello world example and that also throws the same error.

Is this expected behaviour now? Do I need to echo out  the ->result from now on?

Cakes own Event doc talks about returning the Event for callback reasons.

If this is a bug rather than me doing something wrong I'll create an issue on github

Thanks,

Paul

Paul West

unread,
Sep 15, 2016, 6:47:44 AM9/15/16
to QuickApps CMS

Anyone have any idea about this issue?

Can anyone try the demo in the docs and see if they get the same error (http://book.quickappscms.org/developers/events-system.html)

Paul 

Chris

unread,
Sep 17, 2016, 4:58:39 AM9/17/16
to QuickApps CMS
Hi there Paul,

For what I see QACMS's book is out of date, sorry for that. The `trigger()` method now retuns the event object that was used This was changed time ago in order to make it more consistent with Cake's event system, so now QACMS's trigger() is just a shorcut to Cake's event system.


So basically you should use `->data`, as you would when using Cake's:

$event = $this->trigger('Hello', $hello);
print_r($event->data);


"Cakes own Event doc talks about returning the Event for callback reasons"
Listeners should never return the event object itself as there is no need to do it as they are object references.


Best regards and thanks for reporting :)

PS: I'll update the book right now
Reply all
Reply to author
Forward
0 new messages