Answers.Body: <p>I think there is an issue with your namespacing.</p>
  <p>In <code>config/app.php</code>:</p>
  <pre class="lang-php prettyprint-override"><code>'modules' =&gt; [
      'playing' =&gt; modules\site\Playing::class,
  ],
  'bootstrap' =&gt; ['playing'],
  </code></pre>
  <p>In <code>modules/site/playing/controllers/PlayingController.php</code></p>
  <pre class="lang-php prettyprint-override"><code>namespace modules\site\controllers
  </code></pre>
  <p>In your <code>composer.json</code></p>
  <pre class="lang-json prettyprint-override"><code>&quot;autoload&quot;: {
      &quot;psr-4&quot;: {
          &quot;modules\\site\\&quot;: &quot;modules/site/playing&quot;
      }
  },
  </code></pre>
  <p>Then <code>composer dump-autoload -a</code>.</p>
  <p>After this, your <code>https://example.site/actions/playing/playing/tag</code> action should work without a route.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-19T04:47:33.563Z
Answers.Text: This is helpful, thank you!
Answers.UserDisplayName: supazu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-18T10:46:12.370Z
Answers.LastActivityDate: 2022-10-18T10:46:12.370Z
Answers.UserDisplayName: Oli
Answers.Body: <p>Typical controller path - <em>actions</em>/<em>handle</em>/<em>controller</em>/<em>action</em></p>
  <p>So probably it should be:</p>
  <pre><code>'actions/playing/playing/tag =&gt; '/playing',
  </code></pre>
  <p>or</p>
  <pre><code>'actions'/playing/playing/tag =&gt; ['template' =&gt; 'playing'],
  </code></pre>
  <p>Also, did you tell the composer to add a new class?</p>
  <pre><code>composer dump-autoload -a
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-16T05:42:26.080Z
Answers.Text: Hmm so my route works like this `'playing' => 'playing/playing/tag',` but I now get a 403 error and trying to workout why.
Answers.UserDisplayName: supazu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-16T05:47:49.463Z
Answers.Text: Adding `public int|bool|array $allowAnonymous = true;` makes it work but it's got no context of anything it seems; despite being logged in, `Craft::$app->getUser()->getIdentity()` returns null...hence the 403 error I guess.
Answers.UserDisplayName: supazu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-15T06:11:15.773Z
Answers.LastActivityDate: 2022-10-15T06:11:15.773Z
Answers.UserDisplayName: RomanAvr
Body: <p>I'm trying to set up a module with a controller as bit of a learning tool. The learning is not going well so far. Here is my setup:</p>
  <pre><code>- modules
  - - site
  - - - playing
  - - - - Playing.php
  - - - - controllers
  - - - - - PlayingController.php
  </code></pre>
  <p>Inside <code>config/app.php</code> I have: <code>&quot;playing&quot; =&gt; site\playing\Playing::class</code> and it's being bootstraped.</p>
  <pre><code># modules/site/playing/Playing.php
  
  namespace site\playing;
  
  use yii\base\Module;
  
  class Playing extends Module
  {
  
  }
  </code></pre>
  <pre><code># modules/site/playing/controllers/PlayingController.php
  
  namespace site\playing\controllers {
  
  use craft\web\Controller;
  
  class PlayingController extends Controller
    {
      public function actionTag() {
        echo 'This works';
      }
    }
  }
  </code></pre>
  <p>And I have a route <code>'playing' =&gt; 'site/playing/tag'</code>, but when I go to <code>mysite.dev/playing</code> I get a 404.</p>
  <p>I'm sure it's just something super simple I'm missing but I'd appreciate any help!</p>
  
Tags: <modules><controller>
Title: Setting up and understanding a controller
ThreadText: # Setting up and understanding a controller
  
  (Asked by: username_0 on 2022-10-15)
  
  I'm trying to set up a module with a controller as bit of a learning tool. The learning is not going well so far. Here is my setup:
  
  ```
  - modules
  - - site
  - - - playing
  - - - - Playing.php
  - - - - controllers
  - - - - - PlayingController.php
  
  ```
  
  Inside `config/app.php` I have: `"playing" => site\playing\Playing::class` and it's being bootstraped.
  
  ```
  # modules/site/playing/Playing.php
  
  namespace site\playing;
  
  use yii\base\Module;
  
  class Playing extends Module
  {
  
  }
  
  ```
  
  ```
  # modules/site/playing/controllers/PlayingController.php
  
  namespace site\playing\controllers {
  
  use craft\web\Controller;
  
  class PlayingController extends Controller
    {
      public function actionTag() {
        echo 'This works';
      }
    }
  }
  
  ```
  
  And I have a route `'playing' => 'site/playing/tag'`, but when I go to `mysite.dev/playing` I get a 404.
  
  I'm sure it's just something super simple I'm missing but I'd appreciate any help!
  
  **Tags:** modules, controller
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-10-18. Score: 2 | Accepted answer
  
  I think there is an issue with your namespacing.
  
  In `config/app.php`:
  
  ```php
  'modules' => [
      'playing' => modules\site\Playing::class,
  ],
  'bootstrap' => ['playing'],
  
  ```
  
  In `modules/site/playing/controllers/PlayingController.php`
  
  ```php
  namespace modules\site\controllers
  
  ```
  
  In your `composer.json`
  
  ```json
  "autoload": {
      "psr-4": {
          "modules\\site\\": "modules/site/playing"
      }
  },
  
  ```
  
  Then `composer dump-autoload -a`.
  
  After this, your `https://example.site/actions/playing/playing/tag` action should work without a route.
  
  > **Comments:**
  > **username_0**: This is helpful, thank you!  
  
  ---
  
  ### Answer by username_2 on 2022-10-15. Score: 0
  
  Typical controller path - *actions*/*handle*/*controller*/*action*
  
  So probably it should be:
  
  ```
  'actions/playing/playing/tag => '/playing',
  
  ```
  
  or
  
  ```
  'actions'/playing/playing/tag => ['template' => 'playing'],
  
  ```
  
  Also, did you tell the composer to add a new class?
  
  ```
  composer dump-autoload -a
  
  ```
  
  > **Comments:**
  > **username_0**: Hmm so my route works like this `'playing' => 'playing/playing/tag',` but I now get a 403 error and trying to workout why.  
  > **username_0**: Adding `public int|bool|array $allowAnonymous = true;` makes it work but it's got no context of anything it seems; despite being logged in, `Craft::$app->getUser()->getIdentity()` returns null...hence the 403 error I guess.  
  
  ---
  
  