1

I'm migrating from Nitro to DDEV, and on this particular project I'm running im some problems with a custom module.

I'm getting this error:

Error Class "modules\bcsmodule\services\TimeslotService" not found

It's only occurring in DDEV. Everything works fine in Nitro.

I tried ddev exec composer dump-autoload

This is the code:

<?php 
namespace modules\bcsmodule\variables;

use craft\elements\Entry;
use modules\bcsmodule\services\TimeslotService;
use modules\eventmailermodule\EventMailerModule;

class BCSVariable {
   public function test(){
        return 'blabla';
   }

   /**
    * Gets all timeslots available for training and for current user
    */
   public function getAvailableTimeslots(Entry $training): Array
   {
      return (new TimeslotService($training))
         ->allTimeslots()
         ->filterByUser()
         ->filterByMaxUsers()
         ->get();
   }
<?

namespace modules\bcsmodule\services;

use Craft;
use craft\elements\Entry;
use yii\base\Component;

class TimeslotService extends Component
{
    protected $user = null;
    protected $training;
    protected $timeslots;
...
2
  • 1
    Wild guess here, but can you rule out case issues? I’m looking at BCSVariable (not BcsVariable) and wondering how everything’s registered and if each container might handle filename casing differently.
    – Matt Stein
    Oct 13, 2022 at 17:06
  • @MattStein Well, the test() variable is working just fine. Is there something about the TimeslotService ddev does not like? Or do you mean I should try BcsVariable as class name?
    – wesley
    Oct 20, 2022 at 12:11

2 Answers 2

1

Firstly, ensure your directory structure matches your namespacing, so it should be:

- Module.php
- variables/BCSVariable.php
- services/TimeslotService.php

Services are generally registered as components on the module, rather than being instantiated directly.

public function init()
{
    parent::init();

    $this->setComponents([
        'timeslot' => TimeslotService::class,
    ]);

    // ...
}

Which can then be called as follows.

Module::getInstance()->timeslot->get();

See the docs at https://craftcms.com/docs/4.x/extend/services.html

1

Okay.. my problem was that TimeslotService was opened with shorthand PHP so like

<?

DDEV doesn't like this by default so you should always just open with the full opening tag. Hopefully I can help others with this information.

<?php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.