Body: <p>I'm new to craft and slowly learning how to use more advanced features. I'm trying to write a module with a controller. When the route is invoked on a fetch call I get the following error:</p>
  <pre><code>HTTP 404 – Not Found – yii\web\NotFoundHttpException
  Page not found.
  Caused by: Invalid Route – yii\base\InvalidRouteException
  Unable to resolve the request &quot;https:/mysite.nitro/index.php?p=actions/astro/password-global/default&quot;.
  </code></pre>
  <p>I would appreciate any pointers on why I'm getting this error. I have reviewed similar questions on SE for hours, but nothing seems to work.</p>
  <p>I'm using a template generated by pluginfactory.io, which I simplified and adapted a little.</p>
  <p>The main class, PasswordGlobal.php, code is this:</p>
  <pre><code>namespace astro\passwordglobal;
  
  use astro\passwordglobal\services\PasswordGlobalService as PasswordGlobalService;
  use astro\passwordglobal\twigextensions\PasswordGlobalExtension;
  
  class PasswordGlobal extends Module 
  {
      public static $instance;
  
      public function __construct($id, $parent = null, array $config = [])
      {   
          Craft::setAlias('@astro/passwordglobal', $this-&gt;getBasePath());
          $this-&gt;controllerNamespace = 'astro\\passwordglobal\\controllers';
  
          static::setInstance($this);
  
          parent::__construct($id, $parent, $config);
      }
  
      public function init()
      {
          
          // Executes only on the site's front-end.
          // if (! Craft::$app-&gt;request-&gt;getIsSiteRequest()) { return false; }
  
          parent::init();
          self::$instance = $this;
  
          // Registers services  
          $this-&gt;setComponents([
              'passwordGlobalService' =&gt; PasswordGlobalService::class,
          ]);
          
          // Register our site routes
          Event::on(
              UrlManager::class,
              UrlManager::EVENT_REGISTER_SITE_URL_RULES,
              function (RegisterUrlRulesEvent $event) {
                  $event-&gt;rules['passwordGlobalForm'] = 'astro/password-global/default';
              }
          );
  
          // Add in our Twig extensions
          Craft::$app-&gt;view-&gt;registerTwigExtension(new PasswordGlobalExtension());
          
      }
  </code></pre>
  <p>And the controller: DefaultController.php</p>
  <pre><code>namespace astro\passwordglobal\controllers;
  
  use astro\passwordglobal\PasswordGlobal;
  
  class DefaultController extends Controller
  {
  
      protected $allowAnonymous = ['index', 'do-something'];
  
      public function actionIndex()
      {
          $result = 'Welcome to the DefaultController actionIndex() method';
  
          return $result;
      }
  
      public function actionDoSomething()
      {
          $result = 'Welcome to the DefaultController actionDoSomething() method';
  
          return $result;
      }
  }
  </code></pre>
  <p>I'm quite certain the module is loading. I created a twig extension which is loaded by the main class. I can call it on the front end and see the expected output. So the issue is how I'm setting up the route to the controller.</p>
  <p>And just in case, my directory structure inside modules is:</p>
  <pre><code> |-astro
     |---passwordglobal
     |-----src
     |-------controllers
     |---------DefaultController.php
     |-------models
     |---------PasswordGlobalModel.php
     |-------services
     |---------PasswordGlobalService.php
     |-------twigextensions
     |---------PasswordGlobalExtension.php
     |-------PasswordGlobal.php
  </code></pre>
  <p>Thank you!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-09T01:11:30.250Z
Comments.Text: What's the “ID” of your module in the `modules` block of your `app.php` file?
Comments.UserDisplayName: August Miller
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-09T01:13:40.130Z
Comments.Text: @AugustMiller: hi, thank you. the modules app is set like this:
     'modules' => [
          'password-global' => astro\passwordglobal\PasswordGlobal::class,
      ],
      'bootstrap' => ['password-global'],
Comments.UserDisplayName: mauricio
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-09T01:16:53.820Z
Comments.Text: Aha! Ok—try making a request to `?p=actions/password-global/default` or `?p=actions/password-global/default/do-something`. I believe your Module's ID is used as the first segment in the action path, not the namespace! Here's the relevant [Yii documentation](https://www.yiiframework.com/doc/guide/2.0/en/structure-modules#routes) on routing to modules.
Comments.UserDisplayName: August Miller
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-09T01:25:15.840Z
Comments.Text: All right, I tried it out, but I get the same error: ```Unable to resolve the request "https:/mysite.nitro/index.php?p=actions/password-global/default".```
Comments.UserDisplayName: mauricio
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-09T15:10:33.013Z
Comments.Text: @AugustMiller, You were right. Thank you so much. After many attempts I found that I had a compounding issue with my ajax call, that make it hard to figure what was going on. After sorting things out with my JS script your indication worked out great.
Comments.UserDisplayName: mauricio
Tags: <routes><controller><modules>
Title: Invalid Route in module
ThreadText: # Invalid Route in module
  
  (Asked by: username_0 on 2021-10-09)
  
  I'm new to craft and slowly learning how to use more advanced features. I'm trying to write a module with a controller. When the route is invoked on a fetch call I get the following error:
  
  ```
  HTTP 404 – Not Found – yii\web\NotFoundHttpException
  Page not found.
  Caused by: Invalid Route – yii\base\InvalidRouteException
  Unable to resolve the request "https:/mysite.nitro/index.php?p=actions/astro/password-global/default".
  
  ```
  
  I would appreciate any pointers on why I'm getting this error. I have reviewed similar questions on SE for hours, but nothing seems to work.
  
  I'm using a template generated by pluginfactory.io, which I simplified and adapted a little.
  
  The main class, PasswordGlobal.php, code is this:
  
  ```
  namespace astro\passwordglobal;
  
  use astro\passwordglobal\services\PasswordGlobalService as PasswordGlobalService;
  use astro\passwordglobal\twigextensions\PasswordGlobalExtension;
  
  class PasswordGlobal extends Module 
  {
      public static $instance;
  
      public function __construct($id, $parent = null, array $config = [])
      {   
          Craft::setAlias('@astro/passwordglobal', $this->getBasePath());
          $this->controllerNamespace = 'astro\\passwordglobal\\controllers';
  
          static::setInstance($this);
  
          parent::__construct($id, $parent, $config);
      }
  
      public function init()
      {
          
          // Executes only on the site's front-end.
          // if (! Craft::$app->request->getIsSiteRequest()) { return false; }
  
          parent::init();
          self::$instance = $this;
  
          // Registers services  
          $this->setComponents([
              'passwordGlobalService' => PasswordGlobalService::class,
          ]);
          
          // Register our site routes
          Event::on(
              UrlManager::class,
              UrlManager::EVENT_REGISTER_SITE_URL_RULES,
              function (RegisterUrlRulesEvent $event) {
                  $event->rules['passwordGlobalForm'] = 'astro/password-global/default';
              }
          );
  
          // Add in our Twig extensions
          Craft::$app->view->registerTwigExtension(new PasswordGlobalExtension());
          
      }
  
  ```
  
  And the controller: DefaultController.php
  
  ```
  namespace astro\passwordglobal\controllers;
  
  use astro\passwordglobal\PasswordGlobal;
  
  class DefaultController extends Controller
  {
  
      protected $allowAnonymous = ['index', 'do-something'];
  
      public function actionIndex()
      {
          $result = 'Welcome to the DefaultController actionIndex() method';
  
          return $result;
      }
  
      public function actionDoSomething()
      {
          $result = 'Welcome to the DefaultController actionDoSomething() method';
  
          return $result;
      }
  }
  
  ```
  
  I'm quite certain the module is loading. I created a twig extension which is loaded by the main class. I can call it on the front end and see the expected output. So the issue is how I'm setting up the route to the controller.
  
  And just in case, my directory structure inside modules is:
  
  ```
   |-astro
     |---passwordglobal
     |-----src
     |-------controllers
     |---------DefaultController.php
     |-------models
     |---------PasswordGlobalModel.php
     |-------services
     |---------PasswordGlobalService.php
     |-------twigextensions
     |---------PasswordGlobalExtension.php
     |-------PasswordGlobal.php
  
  ```
  
  Thank you!
  
  **Tags:** routes, controller, modules
  
  > **Comments:**
  > **username_1**: What's the “ID” of your module in the `modules` block of your `app.php` file?  
  > **username_0**: @username_1: hi, thank you. the modules app is set like this:    'modules' => [         'password-global' => astro\passwordglobal\PasswordGlobal::class,     ],     'bootstrap' => ['password-global'],  
  > **username_1**: Aha! Ok—try making a request to `?p=actions/password-global/default` or `?p=actions/password-global/default/do-something`. I believe your Module's ID is used as the first segment in the action path, not the namespace! Here's the relevant [Yii documentation](https://www.yiiframework.com/doc/guide/2.0/en/structure-modules#routes) on routing to modules.  
  > **username_0**: All right, I tried it out, but I get the same error: ```Unable to resolve the request "https:/mysite.nitro/index.php?p=actions/password-global/default".```  
  > **username_0**: @username_1, You were right. Thank you so much. After many attempts I found that I had a compounding issue with my ajax call, that make it hard to figure what was going on. After sorting things out with my JS script your indication worked out great.  
  
  ---
  
  ## 0 answers
  
  