<p>Firstly, ensure your directory structure matches your namespacing, so it should be:</p>
<pre><code>- Module.php
- variables/BCSVariable.php
- services/TimeslotService.php
</code></pre>
<p>Services are generally registered as components on the module, rather than being instantiated directly.</p>
<pre class="lang-php prettyprint-override"><code>public function init()
{
    parent::init();

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

    // ...
}
</code></pre>
<p>Which can then be called as follows.</p>
<pre class="lang-php prettyprint-override"><code>Module::getInstance()-&gt;timeslot-&gt;get();
</code></pre>
<p>See the docs at <a href="https://craftcms.com/docs/4.x/extend/services.html" rel="nofollow noreferrer">https://craftcms.com/docs/4.x/extend/services.html</a></p>

CC BY-SA 4.0
2022-10-20T14:29:23.353Z
2022-10-20T14:29:23.353Z
Ben Croker
<p>Okay.. my problem was that TimeslotService was opened with shorthand PHP so like</p>
<pre><code>&lt;?
</code></pre>
<p>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.</p>
<pre><code>&lt;?php
</code></pre>

CC BY-SA 4.0
2022-10-21T11:56:44.713Z
2022-10-21T11:56:44.713Z
wesley
<p>I'm migrating from Nitro to DDEV, and on this particular project I'm running im some problems with a custom module.</p>
<p>I'm getting this error:</p>
<p>Error
Class &quot;modules\bcsmodule\services\TimeslotService&quot; not found</p>
<p>It's only occurring in DDEV. Everything works fine in Nitro.</p>
<p>I tried ddev exec composer dump-autoload</p>
<p>This is the code:</p>
<pre><code>&lt;?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))
         -&gt;allTimeslots()
         -&gt;filterByUser()
         -&gt;filterByMaxUsers()
         -&gt;get();
   }
</code></pre>
<pre><code>&lt;?

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;
...
</code></pre>

CC BY-SA 4.0
2022-10-13T17:06:08.060Z
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
CC BY-SA 4.0
2022-10-20T12:11:13.640Z
@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
<craft3><nitro>
Class not found when migrating to DDEV from Nitro
# Class not found when migrating to DDEV from Nitro

(Asked by: username_0 on 2022-10-13)

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:
allTimeslots()
         ->filterByUser()
         ->filterByMaxUsers()
         ->get();
   }

**Tags:** craft3, nitro

> **Comments:**
> **username_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.  
> **username_0**: @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?  

---

## 2 answers

### Answer by username_2 on 2022-10-20. Score: 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


---

### Answer by username_0 on 2022-10-21. Score: 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.


---

