Answers.Body: <p>This looks like it’d be in a closure registered on the <code>UrlManager::EVENT_REGISTER_CP_URL_RULES</code> event, like this:</p>
  <pre class="lang-php prettyprint-override"><code>Event::on(
      UrlManager::class,
      UrlManager::EVENT_REGISTER_CP_URL_RULES,
      function (RegisterUrlRulesEvent $e) {
          $e-&gt;rules['my/route'] =&gt; 'module/controller/action';
      });
  </code></pre>
  <p>The above explains it almost in context—when creating a route with a plain string, it's interpreted as:</p>
  <pre><code>&lt;module-id&gt;/&lt;controller-name&gt;/&lt;action-name&gt;
  </code></pre>
  <p>The &quot;Module ID&quot; is either defined by the Plugin in question, or when you declare modules in <code>app.php</code>:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  return [
      '*' =&gt; [
          // Lots of other irrelevant (but important) stuff redacted, here!
          'modules' =&gt; [
              'bizniz' =&gt; \modules\mymodule\BusinessStuff::class,
          ],
       ],
  ];
  </code></pre>
  <p>If you had a Controller in your Module (and have <a href="https://www.yiiframework.com/doc/api/2.0/yii-base-application#$controllerNamespace-detail" rel="nofollow noreferrer">properly declared <code>BusinessStuff::$controllerNamespace</code></a>) that looked like this…</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace modules\mymodule\controllers;
  
  use craft\base\Controller;
  
  class FinanceController extends Controller
  {
      public function actionCountBeans()
      {
          return $this-&gt;asJson(['profit' =&gt; (rand() / getrandmax()) * 1000000]);
      }
  }
  </code></pre>
  <p>…your &quot;action path&quot; would be <code>bizniz/finance/count-beans</code>. Yii takes care of mapping the path to your controller—and the <code>UrlManager</code> ensures the key you assign it to acts as an alias.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-15T03:36:53.343Z
Answers.LastActivityDate: 2021-09-15T03:36:53.343Z
Answers.UserDisplayName: August Miller
Body: <p>So here is what I see in a controller:</p>
  <pre><code> $event-&gt;rules['cpActionTrigger1'] = 'plugin/default/do-something';
  </code></pre>
  <p>What does the first part 'cpActionTrigger1' refer to and what does the second part refer to. I am guessing route and template but never see it spelled out in docs.</p>
  
Tags: <craft3><plugin-development><routes>
Title: Can some one explain Event rules in plugins
ThreadText: # Can some one explain Event rules in plugins
  
  (Asked by: username_0 on 2021-09-14)
  
  So here is what I see in a controller:
  
  ```
   $event->rules['cpActionTrigger1'] = 'plugin/default/do-something';
  
  ```
  
  What does the first part 'cpActionTrigger1' refer to and what does the second part refer to. I am guessing route and template but never see it spelled out in docs.
  
  **Tags:** craft3, plugin-development, routes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-09-15. Score: 2
  
  This looks like it’d be in a closure registered on the `UrlManager::EVENT_REGISTER_CP_URL_RULES` event, like this:
  
  ```php
  Event::on(
      UrlManager::class,
      UrlManager::EVENT_REGISTER_CP_URL_RULES,
      function (RegisterUrlRulesEvent $e) {
          $e->rules['my/route'] => 'module/controller/action';
      });
  
  ```
  
  The above explains it almost in context—when creating a route with a plain string, it's interpreted as:
  
  ```
  <module-id>/<controller-name>/<action-name>
  
  ```
  
  The "Module ID" is either defined by the Plugin in question, or when you declare modules in `app.php`:
  
  ```php
  <?php
  
  return [
      '*' => [
          // Lots of other irrelevant (but important) stuff redacted, here!
          'modules' => [
              'bizniz' => \modules\mymodule\BusinessStuff::class,
          ],
       ],
  ];
  
  ```
  
  If you had a Controller in your Module (and have [properly declared `BusinessStuff::$controllerNamespace`](https://www.yiiframework.com/doc/api/2.0/yii-base-application#$controllerNamespace-detail)) that looked like this…
  
  ```php
  <?php
  
  namespace modules\mymodule\controllers;
  
  use craft\base\Controller;
  
  class FinanceController extends Controller
  {
      public function actionCountBeans()
      {
          return $this->asJson(['profit' => (rand() / getrandmax()) * 1000000]);
      }
  }
  
  ```
  
  …your "action path" would be `bizniz/finance/count-beans`. Yii takes care of mapping the path to your controller—and the `UrlManager` ensures the key you assign it to acts as an alias.
  
  
  ---
  
  