This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

nicovdw
nicovdw

For a project I would like to use Events for processing data. The user inputs some fields in the frontend, when he submits, an Event is fired like this: Event::fire('authorx.pluginy.request-foobar', $data);

In the classes folder I created ./plugins/authorx/pluginy/classes/FoobarRequestHandler.php with this code:

<?php namespace AuthorX\PluginY\Classes;

class FoobarRequestHandler
{

    /**
     * Handle request events.
     */
    public function handle($data)
    {
        // Do stuff with the $data
    }

}

And my Plugin.php looks like this:

<?php namespace AuthorX\PluginY;

use Event;
use System\Classes\PluginBase;

class Plugin extends PluginBase
{

    public function boot()
    {
        Event::listen('authorx.pluginy.request-foobar', 'FoobarRequestHandler');
    }

    public function registerComponents()
    {
        return [ ];
    }

    public function registerSettings()
    {
        return [ ];
    }
}

But whenever I try to submit my form, I get the following error message:

Class FoobarRequestHandler does not exist on line 741 of /var/www/public/vendor/laravel/framework/src/Illuminate/Container/Container.php

Any suggestions? It has something to do with the Application IoC binding, but I don't understand how this works. Is this done automatically or do I need to register my Handler in the IoC container? If so, how?

Last updated

nicovdw
nicovdw

Someone told me to use the full name (including namespace) in the boot function. And that did the trick, so for anyone wondering how this works:

    public function boot()
    {
        Event::listen('authorx.pluginy.request-foobar', 'AuthorX\PluginY\Classes\FoobarRequestHandler');
    }

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.