1

I'm making a Craft 3 plugin to read a CSV file and insert the data as Categories.

I used pluginfactory.io to scaffold my plugin.

I can't access craft() in my controller (ImportCsvController.php).

My controller action:

    public function actionDoSomething()
    {
      $categoriesGroups = craft()->categories->getAllGroups();
      return json_encode("hi");
    }

My namespacing:

<?php


namespace workyard\csvtocategoryimporter\controllers;
use workyard\csvtocategoryimporter\Csvtocategoryimporter;
use craft\web\Controller;
use Craft;

The error message:

Call to undefined function workyard\csvtocategoryimporter\controllers\craft()

Any ideas why I can't access craft(). Do I have to "use" something in the namespace section?

4

craft() is gone in Craft 3; instead you will be accessing Craft::$app-> for most things. I'd suggest generating your Craft 3 plugin scaffolding at pluginfactory.io, and if you leave code comments on, it'll give you some hints on how to do stuff like this.

This article might also be helpful to you: So You Wanna Make a Craft 3 Plugin?

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.