4

I'm trying to port a Craft 2 plugin to Craft 3, and don't seem smart enough to work out the namespaces. I've stripped out everything except what the docs recommend, but keep getting Cannot declare class kr37\Calendar37\Calendar37, because the name is already in use Thank you in advance for any suggestions.

Folder structure

composer.json src/Plugin.php

Plugin.php

namespace kr37\Calendar37;

class Calendar37 extends \craft\base\Plugin
{
    public function init()
    {
        parent::init();

        // Custom initialization code goes here...
    }
}

composer.json

{ "name": "kr37/calendar37", "description": "Event calendar with unrestricted repetition", "version": "3.0.18046", "type": "craft-plugin", "minimum-stability": "dev", "require": { "craftcms/cms": "^3.0.1" }, "autoload": { "psr-4": { "kr37\\calendar\\": "src/" } }, "support": { "email": "???" }, "extra": { "handle": "calendar37", "name": "Calendar", "developer": "???", "developerUrl": "???", "hasSettings": "true", "hasCpSection": "true" } }

8

At this point, after much playing around it seems to be working (at least on to the next bit of debugging).

To sum up, it was mostly changes to composer.json, followed by composer remove kr37/calendar37 composer require kr37/calendar37

  1. src/Plugin.php became src/Calendar37.php
  2. Added "class": "kr37\\calendar37\\Calendar37" to the "extra" part of composer.json
  3. Corrected the autoload "psr-4" to "kr37\\calendar37\\": "src/"
  4. Made sure that all the names matched up just right.
  5. This error, "because the name is already in use," should really be "because the name doesn't match up."
  • Thank you for this! I had no idea what was going wrong! – mcclaskiem Apr 23 '19 at 1:59

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.