Craft 3 - Can't access the craft() in plugin controller 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()-&gt;categories-&gt;getAllGroups();
      return json_encode("hi");
    }


My namespacing:

&lt;?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?
craft() is gone in Craft 3; instead you will be accessing Craft::$app-&gt; 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?