<p>Your code should work as you suggested without the additional stuff. </p>

<pre><code>Event::on(
    UrlManager::class,
    UrlManager::EVENT_REGISTER_CP_URL_RULES,
    function (RegisterUrlRulesEvent $event) {
        $event-&gt;rules['waffles'] = 'waffles/syrup/pour';
    }
);
</code></pre>

<p><strong>Clarification:</strong></p>

<p>plugin-name = Waffles</p>

<p>controllerName = SyrupController</p>

<p>functionName = actionPour()</p>

<p>With the information above you should be able to call the function in the controller with waffles/syrup/pour, and as you stated, the <code>rules['waffles']</code> would be your URL.</p>

CC BY-SA 4.0
2018-09-22T18:04:50.283Z
At the time of the question Craft plugins had no automatic controller map included. Now they have it but earlier you had to do what Gustav described
Robin Schambach
CC BY-SA 4.0
2018-09-23T13:08:41.917Z
I had wondered if that was the case. Thanks for clarifying.
Darryl Hardin
CC BY-SA 4.0
2018-09-22T14:42:15.527Z
2018-09-22T14:42:15.527Z
Darryl Hardin
<p>Apparently I figured it out. Would still like a better way of doing this, but here's the solution I found to be working:</p>

<p>In your <code>Plugin</code> class, you have to add a <code>public $controllerMap</code> array. For my example plugin above, here's what I would have to add to that <code>$controllerMap</code> array:</p>

<pre><code>use Very\Waffle\Controllers\SyrupController;

class Plugin extends \craft\base\Plugin
{

    /** @var array */
    public $controllerMap = [
        'syrup' =&gt; SyrupController::class,
    ];

    // other code here, obviously
}
</code></pre>

CC BY-SA 3.0
2017-05-15T11:16:25.837Z
2017-05-15T11:16:25.837Z
Gustavs
<p>I cannot find any documentation that specifies how to link to controller actions which return a rendered template in CP.</p>

<p>Let's say I have a plugin called <code>waffles</code> and my namespace is <code>Very\Waffles</code>. I have a controller named <code>SyrupController</code> and it's residing in <code>Controllers</code> directory (note the capitalized directory name). So the namespace for it would be <code>Very\Waffles\Controllers</code>.<br>
An action <code>actionPour()</code> - how can I register a route that would call this action if I land on the <code>/admin/waffles</code> URL?<br>
I've walked through the steps with a debugger and It's trying to check if a <code>SyrupController</code> exists but how can it, if only <code>Very\Waffles\Controllers\SyrupController</code> exists? Thus it fails to register that route and fails.</p>

<p>Any help much appreciated!<br>
Here's some code:</p>

<pre><code>    Event::on(
        UrlManager::class,
        UrlManager::EVENT_REGISTER_CP_URL_RULES,
        function (RegisterUrlRulesEvent $event) {
            $event-&gt;rules['waffles'] = 'waffles/syrup/pour';
        }
    );
</code></pre>

<p>It shouldn't be possible to link to a controller by using this string, so I'm guessing an array that specifies the <code>SyrupController::class</code>, but there's no documentation about it.</p>

<p>Thanks!</p>

<craft3>
How to link to controller actions in a Craft 3 plugin?
# How to link to controller actions in a Craft 3 plugin?

(Asked by: username_0 on 2017-05-15)

I cannot find any documentation that specifies how to link to controller actions which return a rendered template in CP.
Let's say I have a plugin called waffles and my namespace is Very\Waffles. I have a controller named SyrupController and it's residing in Controllers directory (note the capitalized directory name). So the namespace for it would be Very\Waffles\Controllers.
An action actionPour() - how can I register a route that would call this action if I land on the /admin/waffles URL?
I've walked through the steps with a debugger and It's trying to check if a SyrupController exists but how can it, if only Very\Waffles\Controllers\SyrupController exists? Thus it fails to register that route and fails.
Any help much appreciated!
Here's some code:
    Event::on(
        UrlManager::class,
        UrlManager::EVENT_REGISTER_CP_URL_RULES,
        function (RegisterUrlRulesEvent $event) {
            $event->rules['waffles'] = 'waffles/syrup/pour';
        }
    );

It shouldn't be possible to link to a controller by using this string, so I'm guessing an array that specifies the SyrupController::class, but there's no documentation about it.
Thanks!

**Tags:** craft3


---

## 2 answers

### Answer by username_0 on 2017-05-15. Score: 9 | Accepted answer

Apparently I figured it out. Would still like a better way of doing this, but here's the solution I found to be working:
In your Plugin class, you have to add a public $controllerMap array. For my example plugin above, here's what I would have to add to that $controllerMap array:
use Very\Waffle\Controllers\SyrupController;

class Plugin extends \craft\base\Plugin
{

    /** @var array */
    public $controllerMap = [
        'syrup' => SyrupController::class,
    ];

    // other code here, obviously
}


---

### Answer by username_1 on 2018-09-22. Score: 7

Your code should work as you suggested without the additional stuff. 
Event::on(
    UrlManager::class,
    UrlManager::EVENT_REGISTER_CP_URL_RULES,
    function (RegisterUrlRulesEvent $event) {
        $event->rules['waffles'] = 'waffles/syrup/pour';
    }
);

Clarification:
plugin-name = Waffles
controllerName = SyrupController
functionName = actionPour()
With the information above you should be able to call the function in the controller with waffles/syrup/pour, and as you stated, the rules['waffles'] would be your URL.

> **Comments:**
> **username_2**: At the time of the question Craft plugins had no automatic controller map included. Now they have it but earlier you had to do what Gustav described  
> **username_1**: I had wondered if that was the case. Thanks for clarifying.  

---

