2

Updating a plugin to Craft 3 (also changed its name). I know this is probably something very simple, like capitalization, but can anyone point out what's wrong?

Firefox console shows a 404 for
http://f.test/index.php?p=admin/actions/dryCalendar/calendarOccurrencesField/generateAjaxMiniCalendar
and then
Type error: Response is null

So perhaps Craft is getting the request, but $this->returnJson($response); isn't terminating the request, i.e. Craft continues to try to find a page to match?

My files are set up like this:

DryCalendar.php
controllers/DryCalendar_CalendarOccurrencesFieldController.php

is

<?php
namespace Craft;
//namespace kr37\drycalendar\controllers;
use Craft;
use craft\base\Controller;
class DryCalendar_CalendarOccurrencesFieldController extends BaseController
{
    public function actionGenerateAjaxMiniCalendar() {
        ...
        $this->returnJson($response);    
    }   
}

and in my Garnish js is

Craft.postActionRequest(                   
    'dryCalendar/calendarOccurrencesField/generateAjaxMiniCalendar', 
    data, 
    function(response) {
         ...
    });

Thanks for any help!

1 Answer 1

4

Craft 3 action routes are snake-case rather than camelCase thus your route needs to be plugin-handle/controller-handle/function-name instead of pluginHandle/controllerName/functionName

Your Controllers namespace must be prefix\namespace\name\controllers so in your case it could be kr37\drycalendar\controllers not Craft.

Furthermore you don't need to include your plugin name to the classname anymore. Your controller name can be

CalendarOccurrencesFieldController

Your action will then be drycalendar/calendar-occurrences-field/generate-ajax-mini-calendar

Keep in mind you'll have to create routes of you don't use the action parameter in your request. Currently you are trying to access your controller via cp/site route, not via action route

1
  • Snake-case-was-it, thank you! I think, Robin, that you are rewriting my plugin for me. Very kind.
    – kr37
    Commented Jun 13, 2018 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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