Laravel calls them invokable controllers. In Magento 2, every controller already is one. What differs is where the URL and the HTTP verb live, and what a wrong verb gets back: a 405 in Laravel, a 302 or a 404 in Magento.
How Magento finds a controller
A Magento controller is one class per URL with one method, execute() . There's no route list for controllers. routes.xml gives the module a frontName, and the rest of the URL is the folder and the class name, read left to right. /stock/sku/status lands in Controller/Sku/Status.php .
<router id = "standard" > <route id = "acme_stock" frontName = "stock" > <module name = "Acme_Stock" /> </route> </router>
Enter fullscreen mode
Exit fullscreen mode
Product pages go through the same lookup. The url_rewrite table maps paper-test.html to catalog/product/view/id/31 , and that path is read the same way: frontName catalog , then Controller/Product/View.php .
The class itself is small: 3 constructor arguments and one execute() . It returns a result object.…