1

I'm trying to create a new plugin for my website in Craft CMS 3, just to do some really basic stuff, like parsing an XML file from an external site.

I created it using the plugin creator at https://pluginfactory.io/ as per the craft docs. I have only included the controller and variable components.

I've added it in to my composer.json file, run the composer require command and it has successfully been added to the plugins list with my craft install. However, when I go try and install it from the plugins page, I get this error: "The use statement with non-compound name 'Craft' has no effect in /var/www/html/[websitename]/plugins/[websitename]/src/[websitename].php at line 15"

This is what the code that has been generated looks like (website name redacted):

11 namespace \[websitename];
12  
13 use \[websitename]\variables\[websitename]Variable;
14  
15 use Craft;
16 use craft\base\Plugin;
17 use craft\services\Plugins;
18 use craft\events\PluginEvent;
19 use craft\web\UrlManager;
20 use craft\web\twig\variables\CraftVariable;
21 use craft\events\RegisterUrlRulesEvent;
22  
23 use yii\base\Event;

Does anyone have any idea what is happening here? I've tried reading the plugin docs but I can't see what is going wrong. I assume the plugin creator is generating files correctly, I've used it several times for Craft 2, but this is my first attempt at a Craft 3 plugin.

Thanks, Jai.

3

Please remove the first \ and include a vendor directory

11 namespace [package]\[websitename];
12 
13 use [package]\[websitename]\variables\[websitename]Variable;

The namespace must always consist the package and the plugin name docs

Here is an example

namespace ns\prefix; // <-- see: ns\prefix, not only prefix

class Plugin extends \craft\base\Plugin
| improve this answer | |
  • Yes, this is the answer, thank you @Robin. The plugin vendor is not a required field in the plugin creator, so I assumed it was optional and hadn't filled it in. Adding a plugin vendor makes it all work. – Jai Redden Jun 6 '18 at 11:53

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.