<p>The autoloader won't load files in the folder <code>assets</code> as already stated it is all explained <a href="https://docs.craftcms.com/v3/asset-bundles.html" rel="nofollow noreferrer">here</a>. Your asset bundles should be in a folder called <code>resources</code> otherwise Yii won't register them in its classmap automatically. </p>

<p>Your namespaces must represent your folder structure. The namespace <code>ns\prefix\controller</code> must be for a file in <code>vendor\ns\prefix\src\controller</code> so your namespace <code>ns\prefix\assets</code> will search for a file in <code>...vendor\ns\prefix\src\assets</code> but you have to include the resource on your own via <a href="http://php.net/manual/de/function.require-once.php" rel="nofollow noreferrer">require_once</a> since Yii won't so it because you are in the wrong folder </p>

<p>The easiest solution would be to create a folder <code>resources</code> and use the namespace <code>ns\prefix\src\resources</code></p>

<p>Or you can - like stated in the docs - use your plugin root path as well <code>recoveryfinder\entriesbygroup</code></p>

CC BY-SA 4.0
2018-05-13T17:06:37.290Z
Thanks @Robin Schambach. Here is the [PSR-4 autoloader spec](https://www.php-fig.org/psr/psr-4/). Also, I just read the Yii [docs on modules](https://www.yiiframework.com/doc/guide/2.0/en/structure-modules). It looks like classes in Yii and by extension Craft autoload as long as you follow certain rules.
Eric Snyder
CC BY-SA 4.0
2018-05-13T17:09:39.413Z
I know. That's why I told you to restructure your files because they won't be loaded automatically if you don't follow these rules. I'm not sure what you are trying to say. Only specific folders will be loaded automatically... Not all of them
Robin Schambach
CC BY-SA 4.0
2018-05-12T20:03:52.107Z
2018-05-12T20:31:02.260Z
2018-05-12T20:31:02.260Z
Robin Schambach
<p>I have a custom asset bundle defined in my plugin. My plugin has a controller. The controller has a action:</p>

<pre><code>/**
 * Handle a request going to our plugin's index action URL,
 * e.g.: actions/entries-by-group/entries-by-group
 *
 * @return mixed
 * @throws \yii\base\InvalidConfigException
 */
public function actionIndex()
{
    $this-&gt;view-&gt;registerAssetBundle(EntriesByGroupAssets::class);
    $result = 'Welcome to the EntriesByGroupController actionIndex() method';

    return $result;
}
</code></pre>

<p>As you can see, I am trying to register my asset bundle. I am getting the error:</p>

<blockquote>
  <p>ReflectionException</p>
  
  <p>Class recoveryfinder\entriesbygroup\assets\EntriesByGroupAssets does
  not exist</p>
</blockquote>

<p>My namespaces are:</p>

<pre><code>namespace recoveryfinder\entriesbygroup\controller;
</code></pre>

<p>or in the asset bundle file:</p>

<pre><code>namespace recoveryfinder\entriesbygroup\assets;
</code></pre>

<p>My plugin is in a folder called (note the hyphens):</p>

<blockquote>
  <p>vendor\recoveryfinder\entries-by-group\src\controllers\EntriesByGroupController.php</p>
</blockquote>

<p>It seems that when code gets to ClassLoader::LoadClass I get the error referenced above - class does not exist. It looks to me like ClassLoader is using the namespace as the path spec (without the hyphens) rather than the actual location (with the hyphens).</p>

<p>I must need to set paths in my plugin? If not what is wrong here?</p>

<plugins><craft3>
Trouble finding my custom asset bundle
# Trouble finding my custom asset bundle

(Asked by: username_0 on 2018-05-12)

I have a custom asset bundle defined in my plugin. My plugin has a controller. The controller has a action:
/**
 * Handle a request going to our plugin's index action URL,
 * e.g.: actions/entries-by-group/entries-by-group
 *
 * @return mixed
 * @throws \yii\base\InvalidConfigException
 */
public function actionIndex()
{
    $this->view->registerAssetBundle(EntriesByGroupAssets::class);
    $result = 'Welcome to the EntriesByGroupController actionIndex() method';

    return $result;
}

As you can see, I am trying to register my asset bundle. I am getting the error:

ReflectionException
Class recoveryfinder\entriesbygroup\assets\EntriesByGroupAssets does
  not exist

My namespaces are:
namespace recoveryfinder\entriesbygroup\controller;

or in the asset bundle file:
namespace recoveryfinder\entriesbygroup\assets;

My plugin is in a folder called (note the hyphens):

vendor\recoveryfinder\entries-by-group\src\controllers\EntriesByGroupController.php

It seems that when code gets to ClassLoader::LoadClass I get the error referenced above - class does not exist. It looks to me like ClassLoader is using the namespace as the path spec (without the hyphens) rather than the actual location (with the hyphens).
I must need to set paths in my plugin? If not what is wrong here?

**Tags:** plugins, craft3

---

## 1 answers

### Answer by username_1 on 2018-05-12. Score: 2 | Accepted answer

The autoloader won't load files in the folder `assets` as already stated it is all explained [here](https://docs.craftcms.com/v3/asset-bundles.html). Your asset bundles should be in a folder called `resources` otherwise Yii won't register them in its classmap automatically.

Your namespaces must represent your folder structure. The namespace `ns\prefix\controller` must be for a file in `vendor\ns\prefix\src\controller` so your namespace `ns\prefix\assets` will search for a file in `...vendor\ns\prefix\src\assets` but you have to include the resource on your own via [require\_once](http://php.net/manual/de/function.require-once.php) since Yii won't so it because you are in the wrong folder

The easiest solution would be to create a folder `resources` and use the namespace `ns\prefix\src\resources`

Or you can - like stated in the docs - use your plugin root path as well `recoveryfinder\entriesbygroup`

> **Comments:**
> **username_0**: Thanks @Robin Schambach. Here is the [PSR-4 autoloader spec](https://www.php-fig.org/psr/psr-4/). Also, I just read the Yii [docs on modules](https://www.yiiframework.com/doc/guide/2.0/en/structure-modules). It looks like classes in Yii and by extension Craft autoload as long as you follow certain rules.  
> **username_1**: I know. That's why I told you to restructure your files because they won't be loaded automatically if you don't follow these rules. I'm not sure what you are trying to say. Only specific folders will be loaded automatically... Not all of them  

---

