How to use events

  • I do not understand Events. Events has documented very few. I can not do this. You help me.


    Could your event have a different name?


    How to set up a package event?


    Where is my mistake in this example =>


    Code
    1. return [
    2. 'auth.login' => 'onUserLogind', <-- Working
    3. 'example.login' => 'onUserLogind', <-- Not Working
    4. ];


  • Generally events are triggered by pagekit, so you cannot use random events (you have the possibility to add custom events and trigger them). An event is triggered or dispatch by the application and you catch it e.g. subscribing to it. Every event is identitfied by a unique string (e.g. request), which can be prefixed group events for better understanding, of what they actually could represent (auth.success, view.init etc.)


    To see all triggered events for a site, you can use the debugtoolbar. But then you only got 'used' events (e.g. subscribed events for this page), not all available.


    If you want all events you can catch, you have to work throught the code of pagekit and guess, where which event is triggered with which name, but that is quite hard, as most of the events are generated on runtime (so not hardcoded) or are part of the symfony framework.


    If you got a nice editor with multifile search, try as keyword 'trigger' - everytime pagekit calls that method, an event is dispatched. If you want to search for diffrent event classes, search for files in the project with 'Event' in it.


    Auth events are fixed, you can find them here: https://github.com/pagekit/pag…s/auth/src/AuthEvents.php

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7

    • Helpful

    I don't quite get what you want, so I try to guess - sorry for that. But I think for your task you don't really need events.


    As I understand you want to query something with the node id? You can access every property of the node in the template as they are public. If you want to do more complex things, you could add a helper class which provides query functionality for your desired purpose.


    Then you can add your helper by listening to the view.init event. Here an example of the menu helper, which you can use like $view->menu() in a template.

    PHP: pagekit/app/system/modules/site/index.php
    1. 'view.init' => [function ($event, $view) use ($app) {
    2. $view->addHelper(new MenuHelper($app['menu']));
    3. }, 100],

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7