I'm sure this is a trivial mistake but I can't figure it out (first-time plugin dev).
I have my plugin running with all code in the controller and want now follow best practice and move the workhorse code into a service class.
My main plugin code is
namespace ns\yutulic;
use ns\yutulic\models\SettingsModel;
use craft\models\Section;
public function init() {
parent::init();
self::$plugin = $this;
$settings = $this->getSettings();
$settings->sectionOptions = $this->setSectionOptions();
// Register services
$this->setComponents([
'videoentries' => \ns\yutulic\services\VideoEntriesService::class,
]);
$data = $this->videoentries->scanForVideos(null); // works
}
The relevant controller code is
Class ScanController extends Controller {
public function actionScanEntries() {
// Neiter works :-(
//$data = Yutulic::$plugin->videoentries->scanForVideos($id);
$data = Yutulic::getInstance()->videoentries->scanForVideos($id); // (*)
}
}
And my service code:
<?php
namespace ns\yutulic\services;
use ns\yutulic\Yutulic;
use Craft;
use craft\base\Component;
class VideoEntriesService extends Component
{
public function scanForVideos($sectionId = null) {
echo "Works!!!";
return null;
}
}
Even if I use the example of the docs it fails with the same error message on the line indicated (*) in the controller (but with the 'Foo' class name):
Class 'ns\yutulic\Yutulic' not found
This shouldn't be so hard?