Friday, November 13, 2015

Re: Cakephp3 Events and Listeners

Hi all,
help me about cakephp 3.x in cell

<?php

namespace Templates\Event;

use Cake\Event\Event;
use Cake\Event\EventListenerInterface;
use Cake\Log\Log;

class UsersListener implements EventListenerInterface {

    public function implementedEvents() {
        return [
            'Cell.Templates.action_right_table' => 'action_right_table',
        ];
    }

    public function action_right_table(Event $event, array $action_right_selects) {
        $event->data['action_right_selects'] = ['test'=>'test'];
        return true;
    }

}

===================================

    public function action_right_table($action_right_selects = []) {
        $event = new Event('Cell.Templates.action_right_table', $this, ['action_right_selects' => $action_right_selects]);
        $this->eventManager()->dispatch($event);
        pr($event);die(); ==> null
    }


please help me. result $event null

thanks

Vào 22:56:08 UTC+7 Thứ Năm, ngày 21 tháng 8 năm 2014, Rob Cowie đã viết:
Hi all. I have read the cakephp book on events in version 3, and I cannot seem to get it to work. I am missing a piece of comprehension. 

I have the event dispatch code in a controller:

$event = new Event('Controller.User.login', $this);
$this->eventManager()->dispatch($event);

and I have a model with the following code:

public function implementedEvents() {
    return [
        'Controller.User.login' => 'populateUserPrefs',
    ];
}

public function populateUserPrefs(Event $event, $user){
    Log::write(
        'info',
        'Prefs User Login: '
    );
}

But I am not hitting the populateUserPrefs function. I guess I need to add some code somewhere to register the model as a listener, but I cannot figure out how.


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: