1

I have a simple controller in /craft/plugins/craft-dns-notifier/src/conrollers/DnsNotifierController:

namespace kokesjan\dnsnotifier\controllers;
use craft\web\Controller;

class DnsNotifierController_DbController extends Controller
{
    public function buu() {
        echo "tradada";
    }
}

I would like to access the buu() action from src/templates/index.html twig file via Ajax.

I've had no luck for three days, unable to find any hint anywhere. Nothing I have tried worked. It seems like very easy task to me, but I just can't make it work.

1

I'd suggest generating the code via pluginfactory.io and if you have code comments enabled, it'll give you the URI that you need to trigger your action in the example code.

But essentially it's going to be a kebab-case version of your controller route, with a kebab-case version of your method name (but removing the action preface).

For you, first you should rename your method thusly:

    public function actionBuu() {
        echo "tradada";
    }

And then your URI would be something like:

/actions/dns-notifier/dns-notifier-controller-db-controller/buu

See here for more on controller actions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.